This question is locked. New answers and comments are not allowed.
Hi there, I have a two varieties of Save methods
And
This is on a web-based application, is there a more elegant way to do this? I'm sure I've even had exceptions on the first block, when trying to use OpenAccess.GetContext().
The object was retrieved using
What is the correct way to always ensure dbContext.Add/dbContext.SaveChanges() doesn't fail?
Thanks
public void Save(){ if (Id > 0) { using (var dbContext = OpenAccessContextBase.GetContext(this)) { dbContext.Add(this); dbContext.SaveChanges(); } } else { using (var dbContext = new SystemEntityModel()) { dbContext.Add(this); dbContext.SaveChanges(); } }}And
public void Save(){ using (var cachedContext = OpenAccessContextBase.GetContext(this)) { if (cachedContext != null) { cachedContext.Add(this); cachedContext.SaveChanges(); } else { using (var dbContext = new SystemEntityModel()) { dbContext.Add(this); dbContext.SaveChanges(); } } }}This is on a web-based application, is there a more elegant way to do this? I'm sure I've even had exceptions on the first block, when trying to use OpenAccess.GetContext().
The object was retrieved using
new SystemEntityModel().GetAll<MyEntity>();What is the correct way to always ensure dbContext.Add/dbContext.SaveChanges() doesn't fail?
Thanks