Stateless worker service and api service both referencing same project - entity-framework

I have a service fabric solution that contains the following:
Worker service (.net framework 4.7)
Api Service (.net core 2.0 as VS 2017 does not provide a template for framework api services)
Infrastructure project (.net standard) referencing EntityFrameworkCore
Both services reference infrastructure project.
This gives me issues as the framework service will not load EntityFrameworkCore reference due to it being core.
How do I go about resolving this issue?
Can I force the core to load EF 6.2?
Can I force 4.7 to load EFCore?

Entiy Framework Core is .NET Standard as well, it should load fine on .NET Framework 4.7.
You may need to add the EF Core NuGet packages to the worker service if it doesn't yet use the transitive NuGet package reference style.

Related

Why was SF Stateless Web API template removed?

In the picture below we can see in the year 2018 in VS2017 there is no Stateless Web API template in Service Fabric templates in VS. Why was this removed and what are it's replacements?
Because at the time you took the first screenshot, probably using .NET SDK 2.8 or earlier and SF tools for VS 1.7 and earlier, Service Fabric and the WebApi templates were based on dot net framework only.
The releases that came after Service Fabric .NET SDK 3.0 and SF tools for VS 2.0 , like the one in the screenshot, started a migration to .net standard 2, now you can target dot net framework or dot net core using the same libraries targeting .Net Standard. For A while you had both templates available, now everything is based on core.
The main difference between the old and the new is that the previous templates you used dot net framework 4.6.2 + Owin, now you use AspNet Core with any framework compatible with the .Net Standard 2.
You might get more info from these release notes:
https://blogs.msdn.microsoft.com/azureservicefabric/2017/09/25/service-fabric-6-0-release/
https://blogs.msdn.microsoft.com/azureservicefabric/2018/01/26/service-fabric-6-1-release/

Use EF6 with ASP.NET Core

I am working a new project - and I want to do it using the latest .NET Core.
Reading through the documentation, I came across the comparison between Entity Framework Core and Entity Framework 6.x Comparison. Here
Some of the features that I require like: Spatial Data Type is NOT supported by EF Core. So I CAN'T use it, because Spatial Data Type is required in the Project.
Going through the documentation again, I came across this link on How to use EF 6.x with .NET Core: Here
In the article it mentions (Here):
Before you start, make sure that you compile against full .NET
Framework in your project.json as Entity Framework 6 does not support
.NET Core. If you need cross platform features you will need to
upgrade to Entity Framework Core.
I don't really need my project to be cross platform.
The article is not very clear on how to use EF6 with ASP.NET Core.
I created a new ASP.NET Core Web Application
then I installed EF6 using Nuget Package Manager, and got the following error
I went and removed the netcoreapp1.0 from the frameworks in project.json and added net46 as framework, which removed the error for EF, but now I am getting another error.
So how do I use EF6 with ASP.NET core?
When I use EF6 I have to remove all references to .NET Core, does
this mean I am not using .NET Core? What are the disadvantages of this other than it can't run cross platform?
To stop the second error you need to remove the following from the dependencies section of your project.json:
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
}
For reference, the documentation for referencing the full .NET Framework and Entity Framework 6 from an ASP.NET Core project has a full project.json example.
Removing references to .NET Core does not mean you are not using ASP.NET Core. You are only changing the target runtime platform that your ASP.NET Core project will execute on.
Using ASP.NET Core with the full .NET Framework, you get the benefits of the new project structure and unified story for building web UI and web APIs (e.g. unified Controller class), and you also gain access to the mature, fully-featured .NET Framework, enable use of dependencies and NuGet packages which haven't been ported to .NET Core, for example Entity Framework 6.

How to make ASP.NET Core RC1 work with the GA SDK?

The previous non-GA versions of Service Fabric came with support (and template) for ASP.NET Core RC1. GA removed this support.
I have a project that depends on ASP.NET Core RC1. I would also like to update to the new SDK now.
I can get the asp.net service to run with the latest SDK without any significant changes to code. However creating a ActorProxy or ServiceProxy in the asp.net project fails with exception "The config package was not found". So my asp.net service is unable to communicate with the rest of the services in the application.
How can i fix the issue with ActorProxy and ServiceProxy on ASP.NET Core RC1 service?
Someone else discussed the same problem in the comments of Service Fabric documentation. Vaclav came up with workaround to the bug. Basically the client project requires ConfigurationPackage named "Config". Projects based on the old ASP.NET Core template didn't have the ConfigurationPackage.
For details of implementing the workaround, see:
https://azure.microsoft.com/en-us/documentation/articles/service-fabric-get-started/#comment-2601127160

Shared library for asp.net core app and windows service

I have an ASP.NET Core web app and a Windows Service that both access the same database. I am using Entity Framework Core as an ORM. I would like to be able to create a library package that encapsulates all data access (ie. a Repository) and can be shared by both the web app and the service.
Entity Framework Core appears to only be supported in DNX applications, and Windows Services, as standard Windows applications, cannot reference DNX projects. Is there any way of creating a DNX Windows Service, or another approach that would work?
Creating a standard windows class library with EF 6.x is not an option as the Repository has already been written in EF Core.
Just discovered my mistake, Entity Framework Core is supported in standard windows projects, so it looks like I have my solution: create a Repository class library that accesses the database using EF Core and reference it from both the ASP.NET Core and Windows Service apps.

Is it possible to use EF 4.0 without having a dependence on .NET 4.0

Lets say I build an Service Layer wich deals with POCOs coming out of an repository. The Repository is aware of the EF 4.0 and deals with POCO generation and so on. But that does also mean that my Repository will have a .NET 4.0 dependency and so my Service Layer which consumes the Repository will also have a .NET 4.0 dependency...even if its dealing only with POCOs and has no clue about the Entity Framework at all. Is there any way to work around this?
You could expose your EF entities using a WCF service - your server-side would be .NET 4 specific, obviously - with EF 4, .NET 4, WCF 4 - but the consumer / client doesn't have to be - if can be anything from any other .NET platform to PHP to Ruby to whatever might be calling your service.