This may be a really dumb question because of my lack of understand of EF. Using EF 6. I have a table that has four many to 0..1 relationships with other tables. I am confused with adding data to this table.
Main table:
Key - int
Name - string
MaterialKey - int
Material table:
Key - int
Name - string
I find many examples where one adds a material to the material table first and then adds the Main table data using the value from the material add. This assumes that there is not already a value in the Material table for that entry. I also see a method "context.AddOrUpdateXXX" that some people are using. This method is not available to me in the Model that Entity Developer creates.
I could write a method for each "parent" table (the 0..1 side) that is essentially an AddOrUpdateXXX method. I don't understand how to add that method to my code without duplicating it on each form or losing it every time I make a change to the model in Entity Developer.
What is the best design pattern for this use case?
**EDIT**
I should also mention that I need unique values for the material name.
AddOrUpdate not available in context?
Re: AddOrUpdate not available in context?
The code produced by Entity Developer depends on the code generation template enabled in your model.
Please right-click your *.edml model in Solution Explorer > Open With > select Entity Developer, press OK. Then, navigate to Tools > Entity Developer > Model Explorer > the Templates node. Disable (or remove) a default template EntityObject and add the DbContext template. Save the model to regenerate the code. Is context.DbSetName.AddOrUpdate() available now?
Refer to https://blog.devart.com/entity-develope ... plate.html.
Please right-click your *.edml model in Solution Explorer > Open With > select Entity Developer, press OK. Then, navigate to Tools > Entity Developer > Model Explorer > the Templates node. Disable (or remove) a default template EntityObject and add the DbContext template. Save the model to regenerate the code. Is context.DbSetName.AddOrUpdate() available now?
Refer to https://blog.devart.com/entity-develope ... plate.html.