我有以下情况......
- 海量微ORM
- .NET 框架 4.0
- SQL Server 2008R2
模型:
public class sUser : DynamicModel
{
public sUser() : base(Model.strConnection, "Users", "UserId") { }
}
public class Test
{
public void UpdateUser(string user)
{
dynamic User = GetUser(user);
//Dynamically generated User object has many columns
// I Update following fields...
User.Address1 = "123 Main Street";
User.Address2 = "Suite# 456";
User.CityName = "Princeton";
User.State = "NJ";
User.Zipcode = "08540";
//And update some more fields in Users object
//I could do this...
//var upd = new { Address1 = "123 Main Street", Address2 = "Suite# 456", ...};
//User.Update(upd, User.UserID);
//But would like to pass entire object, so I do not have to form all updated name/value in the update statement
User.Update(User, User.UserID);
//But Users table has a column with IDENTITY SEED,
//And if I pass entire object for update it errors out
//Cannot update identity column 'RefNo'
}
public dynamic GetUser(string userName)
{
dynamic table = new sUser();
var objUser = table.First(UserName: userName);
return objUser;
}
}
用户表有一个 RefNo 列IDENTITY SEED=1
,当我更新整个用户对象时,它会出错,无法更新标识列“RefNo”。我想传递整个对象进行更新,而不是形成长更新语句。
我该如何处理?
谢谢。