.net - Entity framework Update fails when object is linked to a missing child -


The object has a reference to a non-accusative child record, so I'm having trouble updating an object child . like. Tables car and CarColor have a relationship. Car.CarColorId >> CarColor.CarColorId If I load the car with my color record then it

  var results = to the database in Car.x ("CarColor") where x.CarId = 5 Select X;  

I will take the car object back and it's a color object. Now suppose that a carolle was removed some time ago but car records still contain the carcoolor id value. Therefore, when I run the query, the color object is zero because the CarColor record was not present. My problem is that when I attach another color object that exists, I get a store update, the error is included when saving.

  car. Caller = New Collar Database. Save Changes ();  

It appears that no one is trying to destroy the color. How can I work around it?

You have to drop something in the "bare" category, then what I will do in your situation will be to create a SQL view with cars that refer to valid car colors (a sub query count or something similar Kind of) and load cars with valid color references from there.

If you want to set the color of the car that does not have a valid color, then load the car, but without including (), without adding it, and setting the color object directly.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -