Why is MVC4 project Membership DB Table 'Membership' & not 'aspnet_Membership'? - tsql

If you create a new MVC4 web application with the Internet Application Project Template in VS2010, the aspnet DB has six tables :
Applications,
Memberships,
Profiles,
Roles,
Users
& UsersInRoles
If I use the aspnet_regsql.exe tool The tables names are aspnet_Membership etc.. but all have 'aspnet_' MVC4 tables dont have this schema! They have the above names (no 'aspnet_' in sight)
I have even copied the scripts aspnet_regsql.exe uses directly from :
C:\Windows\Microsoft.NET\Framework\v4.0.30319 to use in Sql Server Management Studio
and the results are the same... 'aspnet_' is used.
The MVC4 table columns are slightly different too (there's no MobilePIN column in the Membership table), so is there another provider at work here?
Why does MVC4 produce these slightly different tables?

The providers are not the same, MVC4 introduces new providers - nuget.org/packages/System.Web.Providers

Related

When I used TPH, all the tables recreated

I am developing an EF - MVC 3 application. I have used model first approach, so I have create model first and from that model, EF generated the DB.
I have used a tool called Nuget - Entity Generator - Database designer for generating the database. When I have designed the model first time, I have used the Generate Migration T-SQL and Deploy option of that tool.
Database generated perfectly and it's working fine...
Now I have come across a situation that I have to make a change to the model and I have to use T-SQL Via T4 (TPH) option to update the database.
So previously I used different process to update DB and now I am changing it.
When I use the T-SQL Via T4 (TPH) all the tables get deleted and new tables get created.
How to avoid this ?
I want to only update the table which I have made the changes.
Entity framework 4.3 comes with migration support. This is not available in EF 4.1.
Some links from google:
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx

Change Schema of Entity Framework

I'm using Entity Framework 5 on ASP MVC 4 web site I'm developing.
Because I am using shared hosting which charge for the number of databases I use I would like to run a test site near my production site.
I have two problems:
1) I use Code First and Database Migration. The migration classes seem to embed the schema dbo inside the name of the tables.
How can I change the schema according to the test/production flag
2) How can I change the schema from which EF select data?
Thank you,
Ido.
Both migration and EF take schema from mapping so if you want to change the schema you must update your mapping to use:
modelBuilder.Entity<MyEntity>().ToTable("MyTable", "MySchema");
and control the value of MySchema from configuration but this is really bad idea. One day you forget to change the value and break your production. Use local database for development and test.
As already said: use identical databases (structurally) for development, test and production.
The goal of schemas is to group database objects, like we do with namespaces in e.g. C#, or to simplify permissions for groups of database objects. Not to identify database stages. By using them for the latter you also make it much harder, if not impossible, to use schema appropriately. See for instance this MSDN white paper.
It is much easier to use some database name conventions to indicate their purpose.

Asp mvc mix of database first and code first

I've got an existing database with just one table. This table's most important columns are username and password, and on my asp mvc project i have a model with complementary fields related to a specific user.
I'm new to this technology, so here we go.
First question:
Is it the same to add a connection to a sqlserver from the server explorer (left side in visual studio) than adding the .mdf file to App_Data. I've seen both on some tutorials, it's just that only the former is working for me and it doesn't appends the <add .. /> line to my Web.config file, the latter method throws an 'access denied' box.
Can you make a table from a model?. It doesn't matter if it's empty, or you have to create from sql-studio. This is for my already-coded model, i want it to end up on the same database as the other table.
I want to map models to tables, if is there a straightforward way to do this with a hard-coded config line (i'm done with tutos that do it with the designer), i think is the more sane method to get this code-first-db-first done.
ASP MVC 3,
Visual Studio 2010 Profesional,
Sql Server 2008 r2 Express
I'm not 100% sure this is what you are looking for but why dont you just use the entity framework power tools and reverse engineer the code first model from your existing database, from then on you can just treat everything as if you are doing code first.
Also check out this link

One Entity Framework definition with two storage providers?

Setup
I have a SQL Server 2008 database that is accessed using the Entity Framework on the server.
Each client has a SQL Server Compact Edition 3.5 database for storing data when offline.
I use self tracking entities that are generated from the server defined Entity Framework.
Question
At the moment i have two EDMX defined, one for the server and another for the client, even though they are identical except for the storage provider. I use the self tracking entities from the server and they work fine with the client database. Is there a way to have just a single EDMX? At the moment there is a risk I will make a change to one EDMX and forget to make it to the other. Or am I using the wrong approach?
Note
I do not want to use the sync framework because of complex business logic that needs applying at the server side.
Unfortunately there is no direct way to use single EDMX with multiple storage providers. You must always have separate SSDL part for each provider. The common workaround is to export SSDL, MSL and CSDL as separate files (default setting adds them as resources to assembly) and use some script or pre-build action to create copy of SSDL file with all necessary changes for second provider (there can be also different data types between SQL Server and SQL Server CE). You will than use correct SSDL file per application by specifying it in connection string.
Another "better" solution is not using EDMX and use code first where this problem mostly doesn't exist - but that is architecture change.

Entity Framework 4.3 migrations on existing "Shared" database

We have a huge database with different database schemas for different web applications.
For example: WebApp1 uses Schema1.Tables. WebApp2 uses Schema2.Tables and so on.
Now, I am developing a new web application (WepApp3) which will use Entity Framework 4.3.1. WebApp3 should only be concerned with Schema3 and use only those database object which are part of Schema3. If i create some Entities in WepApp3, How do i migrate these entities to database as schema3.tables? Do i still need to do Initial Migration?
Please help.
I don't think it's possible to have multiple EF models in the same database. EF shouldn't try to touch tables that are nothing to do with its model, but if you wanted to add another EF app to the same database you'd run into trouble because they'd try to share the same MetaData tables.
When generating new models using code-first, you can specify which schema they should be part in the DbContext:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<MyEntity>().ToTable("MyEntity", "Schema3");
}
Is it an option to migrate your schemas out into different databases if there are no shared apps?
It seems to WORK. I started with an existing database. created an mvc app (app1) with couple of models. I then created a schema for this app in database. I specified schema for the models as per your comment. Then I used the power of code based migration script to update the database. Migration script created 2 tables under the new schema without corrupting existing stuff. I noticed EF created __MigrationHistory table with a row with change info.
Then i created another app, a new schema and repeated the migration process with a little tweak in migration script. The script had code to re-create 2 tables of app1. i deleted that code from script. EF then successfully created new tables under new schema and also created new row in __MigrationHistory table with info about new changes. All existing stuff remain unchanged including data.