c# - Entity framework creating separate database corresponding to each class in model -


i have start using of entity framework in asp.net mvc4.

i have created 3 classes in model folder , created controllers every model.

now when run application, has created separate databases corresponding every class of model.

is there way can use 1 database?

are creating separate context each of classes?

public class employee  {     [key] public int empid { get; set; } // < can make suggestion here                                          // , suggest use id rather                                          // empid?  looks better referring                                           // employee.id rather employee.empid     [required] public string fullname { get; set; }     ... }  public class anotherclass {     ... } 

and listing models in context:

public mydbcontext : dbcontext {     public dbset<employee> employees { get; set; }     public dbset<anotherclass> anotherclasses { get; set; } } 

you may want specify connection string name using constructor in context:

public mydbcontext() : base("connectionstring") {  } 

it's important models go in same context.

using context

var context = new mydbcontext(); var employees = context.employees.tolist(); // prefer storing data ilist 

this tells ef query database , store data within employees variable.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -