4
我正在使用.NET框架4.0使用Massive micro-orm和SQL Server 2008R2。使用點符號或索引訪問DynamicModel.Query
// This is my model
public class sUser : DynamicModel
{
public sUser() : base(Model.strConnection, "Users", "UserId") { }
}
和另一類...
using System;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Xml;
using System.Dynamic;
using System.Collections.Generic;
using Massive;
public class Test
{
public dynamic GetUser(string uName)
{
dynamic table = new sUser();
var objUser = table.FindBy(UserName: uName);
//Tried following...
//var objUser = new sUser().All().Where(u => u.UserName.ToString() == uName).FirstOrDefault();
//var objUser = new sUser().All().Where(u => u.UserName.ToString().Equals(uName)).FirstOrDefault();
return objUser;
}
public void GetSomething(dynamic testObj, string user)
{
dynamic User = GetUser(user);
//testObj.CUser = User["FirstName"] + ' ' + User["LastName"];
//Would like to access User object like
//User.FirstName or User["FirstName"]
//And not like this...
foreach (var item in User)
{
testObj.CUser = item.FirstName + ' ' + item.LastName;
}
}
}
我想訪問用戶動態對象像User.FirstName或用戶[ 「姓」]。 這是可能的,或者我錯過了什麼?
任何輸入,非常感謝。
謝謝。
謝謝。您的解決方案解決了問題。 – Rajul