Click here to Skip to main content
16,011,541 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed an application in this i have created a model class named UserModel.cs, in this class i write code as:

namespace Demo2.Models
{
[Table("User_Mst")]
public class UserModel
{
[Key]
public Int64 Id { get; set; }
[StringLength(50)]
public String User_Name { get; set; }
[StringLength(50)]
public String Password { get; set; }
}
public class UserContextDB : DbContext
{
[Key]
public DbSet<usermodel> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<pluralizingtablenameconvention>();
}
}

}

I have done migration using command "enable-migrations -contexttypename UserContextDB"

then i created controller (using template named "MVC controller with read/write actions and views, using Entity Framework").views automatically added correspond to this model, i also defined my own database in connection string named "UserContextDB".

But whenever i tried to save values from "create" view then these values are not saving in my own database, it uses other database.

I want to store all values in my own database. Please provide me help.

Thanks
Posted

1 solution

Use another DBContext for your own classes , the UserContextDB is for roleMemberShip and may cause problem , when i want to add class i add my own DBContext and change roleMemberShip DBContext(UserContextDB) to my DBContext

Code First with Entity Framework 5 using MVC4 and MVC Scaffold[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900