I have following scenario…
- Massive Micro-ORM
- .NET framework 4.0
- SQL Server 2008R2
Model:
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;
}
}
Users table has a column RefNo with IDENTITY SEED=1, and when I update entire User object, it errors out Cannot update identity column ‘RefNo’. I would like to pass entire object for update rather than forming long update statement.
How can I handle this?
Thanks.
Modify Massive.cs
– Add following under DynamicModel class
And under CreateUpdateCommand method add following…
And under foreach loop modify if statement to following…
Above change into Massive library would allow us to update model with identity column. Limitation: Works for Table with one IDENTITY column.