Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Code First approach in Entity framework

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 45
    Comment on it

    In the  code first approach we should be to create the class for defining the attributes for the DBContext

     

    So lets first create a class for defining attributes

     

    public class Employee   
    {  
        public Employee ()  
        {   
          
        }  
        public int EmployeeID { get; set; }  
        public string Name { get; set; }  
    }     

     

    After doing this, we will create a context class that will implement the attributes.

    Database name and table name should be specified in this context class.

    ublic class Context: DbContext   
     {  
         public Context(): base()  
         {  
       
         }  
         public DbSet<Employee> Employees { get; set; }  
     }     

     

    For  consuming  this we need to create a separate application or we will create a class that will implement these methods

    using (var ctx = new Context())  
    {  
        Employee emp = new Employee() { name = "Himanshu" };  
        ctx.Employees.Add(emp);  
        ctx.SaveChanges();                  
    }  

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: