This question is locked. New answers and comments are not allowed.
How do I update an existing entity using AttachCopy method? Is it possible to do it that way?
I know I can use the regular update feature, but I'm trying to safe time and effort because some of my entity objects have over 100 fields with data coming in from 3rd party API.
I've successfully inserted new record using the AttachCopy, but not update an existing record.
Here is in code of what I'm hoping to do, this doesn't work in updating the existing object:
The parameter userMeta object is populated from a form view and has the updated field values. The userMeta class was generated through openaccess database first mapping, so it's the same class definition as entity object.
Thanks!
I know I can use the regular update feature, but I'm trying to safe time and effort because some of my entity objects have over 100 fields with data coming in from 3rd party API.
I've successfully inserted new record using the AttachCopy, but not update an existing record.
Here is in code of what I'm hoping to do, this doesn't work in updating the existing object:
public
ActionResult Update(UserMeta userMeta)
{
var entity = (from u
in
dbContext.UserMetas
where u.UserID == userMeta.userID
select u).FirstOrDefault();
if
(entity !=
null
)
{
var entity = dbContext.AttachCopy(userMeta);
entity.Modified = DateTime.UtcNow;
dbContext.SaveChanges();
}
return View();
}
The parameter userMeta object is populated from a form view and has the updated field values. The userMeta class was generated through openaccess database first mapping, so it's the same class definition as entity object.
Thanks!