AddOrUpdate not available in context?

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
flycast
Posts: 15
Joined: Mon 04 Feb 2019 19:39

AddOrUpdate not available in context?

Post by flycast » 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.

Shalex
Site Admin
Posts: 8838
Joined: Thu 14 Aug 2008 12:44

Re: AddOrUpdate not available in context?

Post by Shalex » Mon 25 Mar 2019 17:27

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.

Post Reply