I only use the EF object to do a lookup and populate the foreign key in my main table entity.Įven with the child objects that are real data, I needs to save the parent first and get a primary key or EF just seems to make a mess of things. However, these definitions already exist and I don't want to create duplicates in the database. Since I've populated these objects myself, EF assumes these are new objects and need to be inserted along with the parent object. For example, the geographic location of the primary entity. In the case of the child objects, many of these refer to lookup tables defining various properties of the parent table. In the application I'm building, the EF object model is not being loaded from the database but used as data objects which I'm populating while parsing a flat file. Since this is being discussed back and forth in the comments, I'll give some justification of why I want my child objects left alone. Why don't I want to save/insert the child objects? If I manually set the properties to null, I get an error "The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable." This is extremely counter-productive since I set the child object to null specifically so EF would leave it alone. How do I force EF to only save the entity I want to save and therefore ignore all child objects? This is causing all sorts of integrity problems. However, it is also trying to save that entity's child entities. When I save an entity with entity framework, I naturally assumed it would only try to save the specified entity.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |