AddOrUpdate not available in context?
Posted: Wed 20 Mar 2019 14:08
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.
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.