예제 #1
0
        static int CreateModel()
        {
            int modelId = 0;

            using (var db = new BikeStoreEntities())
            {
                //approach #1 sproc through the function import
                /*
                var modelIdParam = new System.Data.Entity.Core.Objects.ObjectParameter("modelid", -1);
                var model = new Model { Name = "Domane 5.2", ListPrice = 3499.99m };

                //modeid is an output param
                var result = db.ModelInsert(modelIdParam, model.Name, null, null, null, null, null, null, model.ListPrice,null,null,null);
                modelId = (int)modelIdParam.Value;
                 */

                //approach 2 Used Stored procedure mapping on the Model entity
                //Need to have a select @ the end of the inset sproc
                var model = new Model { Name = "Domane 5.2", ListPrice = 3499.99m };

                db.Models.Add(model);
                db.SaveChanges();

                modelId = model.ModelId;

            }

            Console.WriteLine("New Model: " + modelId);

            return modelId;
        }
예제 #2
0
        static void DeleteModel(int modelId)
        {
            using (var db = new BikeStoreEntities())
            {
                // uses sprocs when mapping set in model
                var model = new Model { ModelId = modelId };

                db.Models.Attach(model);
                db.Models.Remove(model);
                db.SaveChanges();
            }
        }