简体   繁体   中英

Update Linq to SQL Entities

I have a repository pattern in my application, to implement the repository i use Linq to SQL, but apart from the automatically generated entities, i create my own entity classes to maintain abstraction.

The problem is when i try to update entities. Since i fetch from the repositories the custom entities that i created, and not the ones that Linq to SQL created, all changes that i do to the fetch entities are not recorded by the Linq to SQL mechanism.

So when i write:

dbContext.SubmitChanges()

Nothing happens.

What can i do to solve this?

Thanks, Arik

I have done a couple of projects with the same pattern that you are using. What I did was, before calling the dbContext.SaveChanges() , load in the corresponding generated entity or entities from the database and then copy over all the fields from the custom entities that were edited to those loaded entities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM