1

I want to build a API using .NET Core 2.0 that targets the full .NET framework so I can work with Entity Framework 6 and an .edmx file. Is this possible? How do I inject the DbContext generated by the .edmx file?

I want to do this because my project works with a lot of stored procedures and I don't want to keep executing them manually. I'm fairly new to .NET Core so any help you can give me it would be apreciated.

genzop
  • 11
  • 4
  • Have you done your own research and tried something yourself? You will get better answers with specific problems – Milo Dec 27 '17 at 16:16
  • I've done some research and I couldn't find any documentation about working with a .edmx file. You are right my question was too general, I would like to know how can I inject the DbContext generated by the .edmx file. – genzop Dec 27 '17 at 16:30
  • 3
    EF Core does not support EDMX models right now. https://stackoverflow.com/questions/39600602/where-is-the-edmx#39601869 – Dan Schnau Dec 27 '17 at 16:32
  • I'm working with EF6. – genzop Dec 27 '17 at 16:33
  • @genzop - Did you find a solution? I'm in the same creek looking for a stick or something I can paddle with!! – Danimal111 May 17 '18 at 15:58

2 Answers2

0

What I understood what you want to do is to use the new .csproj file format, and target any classic .NET framework, like .NET 4.5.2.

While the project itself works fine, you cannot choose "ADO.NET Entity Data Model" in the "Add New Item" dialog, forcing you to copy over an existing EDMX from a classic .csproj project.

And even after you did that, trying to change the EDMX in the designer and pressing Save just throws me a TargetInvocationException every time, instead of updating the model.

Looking at the log file, the cause gets pretty clear: The designer is not capable of working with the new .csproj files.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The "Content" rule is missing the "AutoGen" property.
    at Microsoft.Verify.Operation(Boolean condition, String unformattedMessage, Object arg1, Object arg2)
    at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.DynamicTypeBrowseObject.<<VSLangProj-FileProperties-get_IsCustomToolOutput>b__38_0>d.MoveNext()

So for now, you're out of luck if you want to keep using the designer.

Ray
  • 7,940
  • 7
  • 58
  • 90
0

You can have your edmx in a separate project that target dot net framework 3.5 or higher, but remember to disable the auto-generated code, because the code generated doesn't work with dot net core. In another project that targets the dot net core, use t4 templates .tt. These files are going to read the edmx file via the file system path.

Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35