SharpRepository EfCoreRepository Initialization in .net Core - sharp-repository

I need help in initializing SharpRepository in .net Core? How do I use dbcontext with SharpRepository? Where in startup can I put initialization code?
I am using Entityframeworkcore with sql server
https://github.com/SharpRepository/SharpRepository
Please post if you have sample code
Thank you

now EfCore repository is stable!
You need to setup DbContext at the same way microsoft suggest
services.AddDbContext<ContactContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
in ConfigureServices inside Statup.cs
you can find a setup guide https://github.com/SharpRepository/SharpRepository/wiki/Getting-started
a full .net core mvc project sample is here:
https://github.com/SharpRepository/SharpRepository/tree/develop/SharpRepository.Samples.CoreMvc
Regards

Related

Web API .Net Core controller generator error 'The item specified is not the element of a list.'

I'm working on a C# web API solution, using .Net Core 3.1 and EF Core 3.1.10.
When scaffolding a controller from a class and a controller, I get this error:
Running the generator 'controller'...
The item specified is not the element of a list.
It this an EF bug?
Or should I look at the class I'm scaffolding?
Cheers, B.
Found the solution.
Turns out the context missed some things, a constructor and a DbSet. Adding those fixed the problem.

Entity Framework 6 for .net Core. In Blazor server side

We have a large Class Library that uses EF6, which is now upgraded to EF6.3 so it can be used with .net Core 3. I want to use that library in a Blazor Server Side App. The problem is, I can't seem to register the connection string. In blazor I am supposed to put the connectionstrings in appsettings.json which I have done, but I can't register it because the normal way to do that (as far as I understand. I am not familiar very familar with blazor, mvc or .net core) is calling the following function inside the ConfigureServices method of the Startup.cs class:
services.AddDbContext<MyDbContext>()
That method is an extension method form the efcore framework which I am not using. What to do if I use EF6.3(4) for core?
I have a WebForms project and there I web.config
As I suspected, it was a dumb question. The problem was the Edmx file, which I linked from a .netframework project. I did that because I need the classes and the edmx file. I used this tutorial for that: https://github.com/aspnet/EntityFramework.Docs/issues/1748.
In order to get it to work I just needed to add an app.config file to the Blazor project and add the connectionstring which is used for the Edmx file.
The services.AddDbContext() was not needed at all.

What are the steps needed in order to isolate ASP.NET Core Identity inside a .NET Standard Class Library targeting a SQL Server database?

I am currently working on a legacy application and we need to re-implement the Authentication and Authorization part in a separate .NET Standard library using ASP.NET Core Identity.
The starting point and implementation path is not clear for me. I installed the following packages:
Microsoft.AspNetCore.Identity
Microsoft.AspNetCore.Identity.EntityFrameworkCore
I don't know how to configure it to use SQL Server or to run migrations.
I apologize if I'm asking simplistic questions.
Please help if you can.
Thanks in advance
You might want to start by going though some of the tutorials. Introduction to Identity on ASP.NET Core
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
I moved a legacy user database over to asp .net identity recently what i ended up doing was creating the identity tables and then creating a sql script which migrated all of my users over to the new data structure. The only trick was converting the passwords.

How does Microsoft.Extensions.Logging work for full .net framework?

The article (Monitor and diagnose Azure Service Fabric applications) indicates following (please note text in bold):
ASP.NET Core logging
Choosing how to instrument your code can be difficult, if you chose poorly and have to reinstrument, you are revisiting and potentially destabilizing your code base. To reduce the risk, developers can choose an instrumentation library such as Microsoft.Extensions.Logging provided by ASP.NET Core. This provides an ILogger interface that allows the provider of your choice to be used while minimizing the impact to existing code. Another nice aspect of this is that the code can be used not only in .NET Core on Windows and Linux, but in the full .NET framework too, giving the ability to standardize your instrumentation code across .NET and .NET Core.
How is this supposed to work because when I tried to add the extensions library (to my service fabric cluster application project that compiles to .net framework 4.5.2), it is attempting to bring down all asp.net core related binaries?
#LoekD's answer is absolutely correct. Here's a .NET Framework example of how to use the Microsoft Extentions Logging framework with Serilog.
public class Program
{
private static void Main()
{
// instantiate and configure logging. Using serilog here, to log to console and a text-file.
var loggerFactory = new Microsoft.Extensions.Logging.LoggerFactory();
var loggerConfig = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File("logs\\myapp.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
loggerFactory.AddSerilog(loggerConfig);
// create logger and put it to work.
var logProvider = loggerFactory.CreateLogger<Program>();
logProvider.LogDebug("debiggung");
}
}
Requires Microsoft.Extensions.Logging, Serilog.Extensions.Logging and Serilog.Sinks.File NuGet packages.
This means that the library 'Microsoft.Extensions.Logging' is compiled against netstandard (1.1), which means it can be used by both full framework (4.5+) applications and dotnet core applications.
Adding the net standard metapackage introduces a bunch of dependencies, but since your project is targeting the full framework, they won't actually be used by your service.

ASP.NET Core EF6 Identity

I am creating a new project in ASP.NET Core with EF6 as the ORM - Note not EF Core.
I am having issues trying to configure the Identity Store.
Here is what I have so far:
Startup.cs
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
This line is causing me the headache. AddEntityFrameworkStores is for EF Core and not the full version of EF 6.
How do I reference the underlying data store for EF6
Thanks
It seems like you have overridden the default data type of Id for ApplicationUser and IdentityRole.
Try AddEntityFrameworkStores<ApplicationDbContext, int>(), or the with type that you have overridden.

Resources