c# - How do I create a read only entity in the entity framework? -
I am loading the graph of the organizations related to the database using the ADO.NET MVC and the unit framework. One institution needs to be modified in memory, but whenever there are other institutions in the graph, then there is no change in the database in the change.
At this time I have tried to use MergeOption.NoTracking and MergeOption.OverwriteChanges but both of them are being ignored and have not modified any changes in the unit set to retain the store. should go.
A snippet of code that I use to load an entity graph is given below:
Quiz Objects Organizations = New Quiz (); ObjectParameter [] Search Parameters = {New Object Parameter ("Competitive ID", Competitive ID)}; Institutions QuizSet Mergeoption = mergeopation .tracking; Var query = entities.ContestantSet Include ("Quiz Questions. Categories Option Answers"). Include ("Answer"). Include ("Quiz.Filter.FiltersFilterAnwers"). Where ("it.ContestantID == @ CONSTESTIDID", search parameter); Competitive Contest = query.First ();
I tried to set up the merge after the query was created but before it was executed.
Any help would be greatly appreciated.
The nature of your problem is the way EF deals with relationships, relationships are first class members. Such institutions are the reason why the object graph, which you are recovering, is a collection of institutions and relationships. All the entities and relationships within the object context are either linked to the object context or disconnected either. This unit is the framework "Platinum Rule" :
When I first saw that an object was linked to ObjectContext, even if I did not explicitly say it In my code, I was a little distraught because I trusted the Anti Framework that what I thought as a "golden rule", not to break it: that does not do anything which I especially Not to do this said. Once I understood why the organization was getting automatically attached to references, when I was connecting them with a graph- and why it was necessary-I decided that this unit should be the Platinum Rule Framework because it
"Golden Rule" says that EF will never be that which you have explicitly rejected. Did not tell it.
So, the "read-only" unit is a separate unit. You can get it done by the way you have already done it or if you call the method different on objectcontact, the organizations in the object graph can be separated from the object contact.
Comments
Post a Comment