Can't generate EF entity code from within VS

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
rmagruder
Posts: 47
Joined: Thu 26 Jun 2014 17:12

Can't generate EF entity code from within VS

Post by rmagruder » Tue 27 Jan 2015 16:31

I think somehow I've broken something in my project. I'm not sure how to best fix it.

The project has an EDML file called 3DEntities.edml. Under that node, there are dependent files which include:
3DEntities.Context.tt
3DEntities.edmx.Diagram (I had migrated this from an edmx so leftover?)
3DEntities.edps
3DEntities.info
3DEntities.ModelDiagram.View
3DEntities.tt
|_ 3DEntities.cs
|_ TABLE1.cs
|_ TABLE2.cs
|_ etc...

I don't know why there are two .tt files. The TABLE1 and TABLE2 are just stand ins for the 20-odd entities brought in from Database-First generation.

I edit the EDML in the VS-integrated EDML designer and add a new table (say, TABLE3). It is in the designer, but I cannot force a generation to occur. Not by saving the EDML, not by saving the TT files, and not by right clicking on anything and saying "Run Custom Tool". Compiling the app doesn't generate either, just compiles what's there.

If I open the EDML in Entity Developer standalone, and hit F7 to generate code, it will happily spit out a ton of new entities, including the ones already there, albeit with new file names, and namespaces.

So, I'm thinking the structure of the above files is wrong, with maybe some kind of disconnect between the EDML and TT files, and somehow saving EDML isn't updating the generated TT files or the files under them which should update. Can you point me to anything that might help me get the model and support files back into a state where saving the EDML changes updates/generates the entities that are currently under that context.tt?

Thanks

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

Re: Can't generate EF entity code from within VS

Post by Shalex » Thu 29 Jan 2015 14:25

rmagruder wrote:I had migrated this from an edmx
Please leave 3DEntities.edml, 3DEntities.edps, 3DEntities.ModelDiagram.View in your project, but remove all other model and *.tt files. Delete also *.cs files generated by old (*.edmx) model.
rmagruder wrote:I edit the EDML in the VS-integrated EDML designer and add a new table (say, TABLE3). It is in the designer, but I cannot force a generation to occur.
It seems like you did not enable any template in *.edml. For this, open *.edml and navigate to the Tools > Entity Developer> Model Explorer window, right click on the Templates node > New Template > select a predefined template (e.g.: DbContext template). Save the model to regenerate the code.

rmagruder
Posts: 47
Joined: Thu 26 Jun 2014 17:12

Re: Can't generate EF entity code from within VS

Post by rmagruder » Thu 29 Jan 2015 15:34

Okay, I'll give it a go. Thank you!

rmagruder
Posts: 47
Joined: Thu 26 Jun 2014 17:12

Re: Can't generate EF entity code from within VS

Post by rmagruder » Mon 02 Feb 2015 19:42

This worked great. Thank you :)

rmagruder
Posts: 47
Joined: Thu 26 Jun 2014 17:12

Re: Can't generate EF entity code from within VS

Post by rmagruder » Mon 16 Mar 2015 14:44

Hate to be back on this again, but I just added a Model-defined function to my EDML in Visual Studio 2013. I save, compile, etc...and I never see any hint of generation. I *do* see the entry was made in the XML for the EDML file, but it didn't go any further.

I do have a DBContext Template in the Model Explorer and everything appears to be enabled, but I can't seem to find the enchantment required to make it update my context .cs code on save.

The only thing I can think to do is open it in the standalone Entity Developer and use the handy "Generate code" menu item.

Thoughts?
Randy

rmagruder
Posts: 47
Joined: Thu 26 Jun 2014 17:12

Re: Can't generate EF entity code from within VS

Post by rmagruder » Mon 16 Mar 2015 15:17

(By the way this is with Oracle)

It's actually even worse. I Just loaded the EDML up in standalone Entity Developer, and the model-defined function is there, and is valid, but when I hit generate, and it DOES generate all class files as well as the context class file, there is no [EdmFunction] generated method for my model-defined method. Why won't my model-defined method generate a C# function in the context class?

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Can't generate EF entity code from within VS

Post by MariiaI » Wed 18 Mar 2015 11:54

but I just added a Model-defined function to my EDML in Visual Studio
....
I do have a DBContext Template
This is an expected behaviour. The code for the model-defined functions is not generated for the DbContext object, an ObjectContext object should be used (i.e. the EntityObject template in Entity Developer).
Please refer to these articles:
http://blog.devart.com/model-defined-fu ... loper.html
http://www.entityframeworktutorial.net/ ... h-EDM.aspx (the Entity SQL section)
https://msdn.microsoft.com/en-us/librar ... 00%29.aspx

rmagruder
Posts: 47
Joined: Thu 26 Jun 2014 17:12

Re: Can't generate EF entity code from within VS

Post by rmagruder » Fri 20 Mar 2015 18:32

I do see that. I understand now.

I do, however, have a question if anyone sees this and knows the answer. If I am working within a DbContext, if I want to add this functionality manually to a partial class with the EdmFunction (or DbFunction) attribute, how can I get from a DbContext to an ObjectContext QueryProvider. I can get the ObjectContext but the compiler says that the QueryProvider property is not accessible to me, even though it exists.

I hate the fact that it seems like DbContext is the 'recommended' way to do EF, but it seems like there's now missing functionality. Retooling the project to go back to ObjectContext just seems....wrong.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Can't generate EF entity code from within VS

Post by MariiaI » Mon 23 Mar 2015 13:50

rmagruder wrote:I do, however, have a question if anyone sees this and knows the answer. If I am working within a DbContext, if I want to add this functionality manually to a partial class with the EdmFunction (or DbFunction) attribute, how can I get from a DbContext to an ObjectContext QueryProvider. I can get the ObjectContext but the compiler says that the QueryProvider property is not accessible to me, even though it exists.
This is an Entity Framework general question and it is beyond the scope of our support. We provide support only on the provider-specific questions.
JIC: probably, this link would be helpful (see Conclusion).

If you encounter any provider-specific difficulties, please contact us.

Post Reply