Error with unflatting to LinqToSql entity

Sep 5, 2011 at 1:45 PM


I've been using Value Injecter for some time and I found it great.

But, 2 days ago, it threw me an excpetion that I couldn't resolve it so far. When I try to map a DTO to a LinqToSql object grabbed from database, LinqToSql threw a "ForeignKeyReferenceAlreadyHasValueException".

For example, I get an existing People object from DB, and I want to map it with my DTO, that is coming from my view (I'm using ASP.NET MVC 2). So, this way I thought that I could fill People object with the modified values, but the exception I mentioned occurs.

I've tried to create a Deatch() method, but other exception occured. For example, People have a child entity Phone and when I get People from DB, this People has 2 Phone objects relationed. So, I deatch People to make Phone to its default null value. But, when I map PeopleDTO to this People, LinqToSql throws an "object null reference" exception on Phone entity (not on People, but on Phone entity).

I've tried all kind of stuff, but nothing helped me. Tried to Attach an entity, sometimes worked, sometimes didn't and when it worked, it took very ver long (3x times slower to do a SubmitChanges).

Any ideas how can I map this LinqToSql entities? I was thinking about something more generic, because in my example, People has only one child (Phone), but I have real world entities tha have about 10 or more FK associations.

I also had tried other mappers, but when no exception occured, no changes were submitted. It's like DataContext doesn't recognize the changes were made. I read some things such as "some mappers don't work when updating a LinqToSql entity, because these mappers update entity fields and not entity properties", but I don't know if it is the case of Value Injecter.


Sep 5, 2011 at 5:11 PM

first try to do this without valueinjecter, when you succeed start optimizing and use it