ASP .Net Identity and Entity Framework Database - entity-framework

I'm developing an event page using entity framework and asp net identity 2.0 and I'm new also with this kind of tools.
If I create a new project that using template visual studio, it's automatically create a DB with several table. and also there are many code that I don't need in that template. (template -> project mvc with already installed authentication).
I've read several tutorial, but for creating from scratch my step is like this :
Create a DB
Create simple mvc project and install package nuget for asp net identity and EF framework
Set the connection strings
Create the code and EF will automatically created the table if not exist on DB?
I'm not really sure with number 4.. and are my steps are correct?
Thanks

Just follow the tutorial step by step, this will teach you how to create and build your project in a very simple way.
Getting started with ASP.NET Identity:
https://www.captechconsulting.com/blogs/Customizing-the-ASPNET-Identity-Data-Model-with-the-Entity-Framework-Fluent-API--Part-1
and here is a good Introduction to ASP.NET Identity:
http://tektutorialshub.com/asp-net-identity-tutorial-basics/

Related

Use ADO.NET Entity Model (.edmx) in Blazor .Net Framework

I like to use a previous ADO.Net Entity Model, stored in another project (in the same solution) and imported like DLL in Blazor's ASP.NET Framework (not Core).
Unfortunately when i try to connect my context I receive that error: "No connection string named 'MyDBEntities' could be found in the application config file.".
I tried to configure appsettings.json:
"ConnectionStrings": {
"MyDBEntities": "xxxxxxxxxxxxxxxxxxxx"
}
and the startup.cs:
services.AddScoped<MyDBEntities>((_) => new MyDBEntities(Configuration.GetConnectionString("MyDBEntities")));
What am I doing wrong?
After some research, the best solution for implement a system like ADO.NET in .Net 6 with Blazor is to use EF Core Power Tools, a useful design-time DbContext features for connect your DB (in my case is SQL Server) and automate the creation or update of your tables.
It's very simple to install, configure and use like ADO.NET.
For more information about how install in your Visual Studio Solution, here is the link:
https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools

What is a good action plan for database first connect data from postgresql to a c# project with dot net core and using entity framework core

I need to successfully do database first connect data from postgresql to a c# project with dot net core and using entity framework core.
Am familiar with mvc with sql and entity framework full database first (in this case we use the Entity Data Model Wizard which makes things easier.
I am not familiar with EFcore, dot net Core and also postgresql.
I successfully did a code first connect data from postgresql to a c# project with dot net core and using entity framework core, and using npgsql, on a console app.
Now I need to do database first web application, and should I try to edit my existing code first console app to try database first? Or should I build a new mvc project from scratch?
Also, if I do from scratch, what will be a good sequence I try
eg 1. try entity framework core tutorial first (which uses sql and is only code first),
then2. try to see how to do database first using reverse engineering
then3. try to replace the sql with postgresql
or are there any other methods that are better?
Scaffolding works with postresql.
Create project which will have your database entities and context. Install efcore tools and npgsql for this project.
Then, inside new project try this command using cmd:
dotnet ef dbcontext scaffold "Host=localhost;Database=databaseName;Username=user;Password=password" Npgsql.EntityFrameworkCore.PostgreSQL -t table1 -t table2 -o outputFolder
You dont have to pass -t parameters if you want to scaffold whole database.
If some error happens, try --force argument.
You should be able to use this database via context created by ef core.

Deploy EF Core SqlServer Database to Production Environment

Have developed new ASP.NET Core 1.1 MVC web site using Entity Framework Core and MSSQL LocalDB Server. I am new to the Entity Framework world as this is my first EF project. My production environment hosting provider creates an empty MSSQL database and then I must update that with whatever schema is needed. So how do I update or migrate the development schema into the empty production database on production server?
Is there someone or some document that can guide me thru this process. It would be much appreciated.
Orgbrat
Check con this MVA: https://mva.microsoft.com/en-US/training-courses/implementing-entity-framework-with-mvc-8931?l=e2H2lDC3_8304984382
I would recommend going over the whole course but you can focus on "Managing the Database" - "Code First Migrations". Hope this helps.

Way to use Entity Framework with Classic Asp

In my company, we have almost all the systems running on classic asp with the logic layer in dlls made by vb6. We use sql server and it's used via stored procedures.
Recently I found how easy is to connect to a procedure using entity framework, and we are trying to avoid the usage of vb6, and for tests purposes, i create a project in .net similar to the ones we use in vb6 with entity framework connecting to the procedure, and generating the tbl and using regAsm to register the dll, I could use it in the classic asp, but when i try to access the method that access the procedure, it gives me the return:
No connection string named 'xEntities' could be found in the application config file.
Where xEntities is the name of my context.
We can't migrate everything to the asp.net because of the time, but it will be very good if we stop using vb6.
Any suggestions?
Thanks.
Have you tried creating a web.config file with the appropriate Entity Framework sections in your web site folder? It is possible to have a web.config in a folder with an ASP Classic web site.

Publish Entity-Framework Code-First Migrations with no Context in the startup project

I am building a solution with the following Projects:
Main.Data - Class Library project
Main.API - Asp.NET MVC WebApi - references Main.Data
Main - Asp.NET MVC 4 web application - references Main.API
I have a MyContext : DbContext class located inside Main.Data project.
I have also successfully issues enable-migrationsconsole command on Main.Data project, and I am successfully using LocalDB as an SQL server for my data and for upgrade-database migrations.
The problem starts when I am trying to publish Main project to Windows Azure website.
The Publish Profile that is automatically created using Import from a Windows Azure web site does not seems to recognize that I am using Entity Framework Code First solution, and so I can't enable Execute Code First Migrations as I would like to. Instead, I can only enable Update database scripts.
I am using Visual Studio 2012 with Entity Framework 5.0.0 (Since the beginning of the project).
Just to verify, I have tried to add a temporary MyContext class inside the Main Project and to enable-migrations on the Main project, and after that my Publish Profile automatically detected Entity Framework Code-First.
That is, of-course, not a solution (or is it?)
Here are some relevant threads:
This is the base learning tutorial.
This explains deployment options, but no troubleshooting.
This actually gives a few ideas to try, but all seems unnatural.
I am looking for a clean stable solution. Do I have to put my Context class inside the Main Project?
Thanks in advance
I can now enable Execute Code First Migrations when I create a publish profile.
Here is what I did to achieve it:
Inside Main/Web.config I changed the name of the connection string to the FQN of the context class: Main.Data.MyContext.
Add a reference from Main project to Main.Data Project (which was not needed until now).
This does the job for me.If anyone got a better or more educating answer, I would be happy to hear it.