Data context Class Missing in Identity - .net-core

So I have a ASP Core 3.1 project and have managed to scaffold out via EF all the rest of my existing tables from my SQL server.
These all work fine and do as i need them to.
However when i go to add Identity to the project using my existing ASP User tables i cannot find the Data context class in the Scaffold menu.
I have already tried re-loading Identity, changing the base, and changing the startup file to look at the current database connection
Any help would be appreciated

I had the same problem. I was inheriting the superclass DbContext in my ApplicationDbContext. Since I was using Identity platform, changed it to IdentityDbContext. It fixed my issue.

Related

Can I Use DbContext for creating asp.net identity user tables instead IdentityDbContext

I want to make identity user tables in my asp.net core web API project and I want to make it with code first approach that's why i want to use DbContext as compared to IdentityDbContext. Can I do this? If Yes, then how?

ASP.NET Core Entity Framework identity discriminator cannot be NULL

I'm moving an application from ASP.NET to Core is driving me nuts. A discriminator column has been added to the AspNetUsers table. The app is using EF Core 5 code first and I understand this has something to do with Table Inheritance which we do not want.
Well this is really nasty as can not access the property from my controller as it seems to want to be the calling class (ApplicationUser) or even set the SQL type to 'allow NULL'.

Configure database for MVC authentication

I've been Googling terms like
configure database for mvc authentication
But I can't find anything from this decade that relates to my configuration.
I've created an MVC application using .NET Framework 4.6 with authentication support (database first). Now where do I find step-by-step instructions for creating the database tables and configuring MVC to use them?
Thanks for any tips!
The correct thing to google for is 'ASP.NET Identity'.
If you generate an MVC app straight from one of the templates it will generate a number of classes to handle security and identity.
One of these classes will implement interface IUserStore. The class provided will inherit from Microsoft.AspNet.Identity.EntityFramework.UserStore<TUser>, and uses Entity Framework to check the database if the tables exist, and create them if they are not there.
If you are uneasy about giving your application enough privileges to modify your data schema (ew!), you can create your own class that implements IUserStore and plug that into the system.
It's a big topic, but hopefully this is enough to get started with.

Why does DataContext class create a new database?

Guys I am a new bee to asp .net mvc 3.
In the MS Visual Web Developer Express 2010, I created a new project using Visual C# / Web / ASP .net MVC 3 Web App using a form authentication template. I deleted all the controller and view files and added my own. I added a new sample.mdf database in the App_Data folder and changed the connection string accordingly and created country model.
But when I create CRUD controller for the country model it asks me for the DataContext class. It does not accept empty and I have to mention DataContext class. And when I create a DataContext class, it creates a new database of same name as the DataContext class. It does not use the database that I specified in the web.config file.
I want Country model data to be added in the sample.mdf file and not in the context database.
Please help... Thank you.
You can pass in the connection string to use in context constructor. That way you can use any database you wish.
A Data context class is simply just a class that maps your model classes to tables in the database. In the web config the connection string name should be the same as your context class (datacontext.cs):
<add name="datacontext" connectionString="[connectionstringhere]" />
If the connection string pointed to a SQL CE database that doesn’t exist... When you run the application, EF detects that the database didn’t exist and automatically creates it from the models set in the data context class.

How to consume an EF Model in a seperate project within a ASP.NET Solution correctly?

I am trying to find a way to have my Entity Framework model in a seperate project within my ASP.NET solution.
Currently I have my DataManager project (which contains my EF model and some classes) and a second project which contains all my web project files.
The problem that I have come across is that I have a database connection string in a App.Config file in my DataManager project and the same connection string in my Web.Config from my web project. I basically have a duplicate connection string.
Is there a way to only use only one connection string in my project (preferably from my web.config)?
My only concern is that when it comes to compiling my project I will not be able to change the connection string in the App.Config contained in my DataManager project.
I would be grateful if someone could help me in the correct way of having a seperate project to contain my EF model. Or suggestions on better ways.
Many Thanks!
In my project I have my EF in a domain layer and my UI in a seperate layer. The UI contains the webconfig file which in turn has the connection string that EF uses. So yes it's completely acheivable. My webconfig will superseed the app.config setting.
My suggestion it terms of layering your app would be to look at some DDD. I'm using EF4 in conjuction with MVC and the repository pattern, which seems an elegant fit. I'm not saying you need to use MVC, but it's certainly worth looking at having a domain layer for ef4.
This is the application I've used as my guide. Note this is based around mvc, but the domain aspect could be true of any application http://mvcsamples.codeplex.com/

Resources