Showing posts with label Entity Framework. Show all posts
Showing posts with label Entity Framework. Show all posts

Thursday, July 2, 2015

how to work with Entity Framework project


Steps to create entity frmawork project
1.Create a class library project for Context name YourProjectNameContext.
2.Right click the project and add new edmx.
3.Before creating edmx ensure that your Database is ready with proper relationship.
4.Open edmx file -> right click -> Add code generation Item -> select ADO.Net Self-tracking Entity Generator.
5.Add new Class library project for Entity named yourProjectNameEntities
6.Drag the .tt from Context project and drop it to Entity project.
7.Delete .tt files from Context project.
7.Reference - install entity framework,add refernce system.runtime.services.
8.Create your website/webapi project and add above created projects to here.


Regards
Santosh Singh
Rain Water Harvesting System Click here for info

Best Android Phones Below Rs- 5000

Wednesday, August 14, 2013

Add new record in database usinbg Entity Framework/Entity Framework - Inserting Data to Database

 For adding new objects to the Entity Set, you need to create an instance of an Entity type and add the object to the object context.   
 public bool StudentDetail(StudentDetail objstudetail)  
 {  
       StudentDetail studetail = new StudentDetail();  
       studetail.ID = objstudetail.ID;  
       studetail.Name = objstudetail.Name;  
       studetail.Age = objstudetail.Age;  
       studetail.Address = objstudetail.Address;  
       studetail.City = objstudetail.City;  
       try  
       {     
           using (DBEntities context = new DBEntities())  
           {  
                context.studetails.AddObject(studetail);  
                context.SaveChanges();  
           }  
       }  
       catch (Exception ex)  
       {  
        throw ex;  
       }  
       return true;  
  }