我正在使用带有 .NET 框架 4.0 的 Massive micro-orm 和 SQL Server 2008R2。
// 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 或 User["FirstName"] 这样的用户动态对象。这是可能的,还是我错过了什么?
任何输入都受到高度赞赏。
谢谢。