jkmills78
8/16/2016 - 11:34 AM

Add data to table using Entity Framework.

Add data to table using Entity Framework.

using AppModel.DTO;
using AppModel.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;

namespace AppRepository
{
    public class MyRepository : IMyRepository
    {
        private myEntity context; 
 
        public int Add(Data data) 
        {
            using (context = new myEntity()) 
            { 
                DBTable dbTable = new DBTable(); 
                dbTable.MyID = data.MyID;
                dbTable.MyFirstName = data.MyFirstName;
                dbTable.MyLastName = data.MyLastName;
                dbTable.MyDOB = data.MyDOB;
 
                context.DBTable.Add(dbTable); 
                return context.SaveChanges(); 
            }
        }
    }
}