static void UpdateModel(int modelId) { using (var db = new BikeStoreEntities()) { //ModelSelectByKey mapped to entity "Model" var model = db.ModelSelectByKey(modelId).FirstOrDefault(); if (model != null) { //the following is necessary if the return type of ModelSelectByKey is complex type ModelSelectByKey_Result // ModelSelectByKey uses the default /* Model m = new Model(); m.ModelId = model.ModelId; m.Name = model.Name; m.ManufacturerCode = model.ManufacturerCode; m.CategoryId = model.CategoryId; m.Description = model.Description; m.Features = model.Features; m.StatusId = model.StatusId; m.ManufacturerId = model.ManufacturerId; m.ListPrice = model.ListPrice; m.ImageCollection = model.ImageCollection; m.CategoryCustomData = model.CategoryCustomData; m.ManufacturerCustomData = model.ManufacturerCustomData; db.Models.Attach(m);*/ // make the change - needs to happen after the attach, otherwise the change // will not be registered //m.Features = "500 Series OCLV Frame"; model.Features = "500 Series OCLV Frame"; db.SaveChanges(); } } }
static void SelectSingleModel(int modelId) { using (var db = new BikeStoreEntities()) { // option #1 Call db context method linked to sproc var model = db.ModelSelectByKey(modelId).FirstOrDefault(); //Option #2 - Directly call sproc /* var modelIdParam = new SqlParameter("@modelid", modelId); var model = db.Database.SqlQuery<ModelSelectByKey_Result>("product.ModelSelectByKey @modelID", modelIdParam).FirstOrDefault(); */ Console.WriteLine("Selected Model:"); if (model != null) { Console.WriteLine(model.ModelId + " | " + model.Name); } } }