简体   繁体   中英

.NET Core 2.0 API with EF6 and .edmx file?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM