Beispiel #1
0
 public IList <Customer> GetRecords()
 {
     using (var db = new YourDatabase())
     {
         var list = (from c in db.Customers select c).ToList();
         return(list);
     }
 }
Beispiel #2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            var dbPath = Path.Combine(env.ContentRootPath, "App_Data", "ProgCoreEf.mdf");

            YourDatabase.ConnectionString = !env.IsDevelopment()
                ? "production"
                :  String.Format("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename={0};Initial Catalog=ProgCore_Ef;Integrated Security=True", dbPath);
            app.UseDeveloperExceptionPage();
            app.UseMvcWithDefaultRoute();

            var db = new YourDatabase();

            db.Database.EnsureCreated();
            //db.EnsureSeedData();
        }
Beispiel #3
0
 public void Save(Customer customer)
 {
     using (var db = new YourDatabase())
     {
         var existing = (from c in db.Customers
                         where c.Id == customer.Id
                         select c).SingleOrDefault();
         if (existing == null)
         {
             db.Customers.Add(customer);
         }
         else
         {
             existing.FirstName = customer.FirstName;
             existing.LastName  = customer.LastName;
         }
         db.SaveChanges();
     }
 }