public void AddLocation_Item( int typeId, int trashId, decimal amount, string itemName,string address, decimal longitude, decimal latitude) { try { Location_Item addModel = new Location_Item() { Id = Guid.NewGuid(), Address = StringHelper.LimitLength(address, 100), Longitude = longitude, Latitude = latitude, TypeId = typeId, TrashId = trashId, Amount = amount, ItemName = StringHelper.LimitLength(itemName), LastAddTime = DateTime.Now }; if (trashId > 0) { Trash trash = db.Trashes.Where(c => c.TrashId == trashId).FirstOrDefault(); if (trash != null) { addModel.Price = trash.DefaultPrice; } else addModel.Price = -1.0M; } db.AddToLocation_Items(addModel); db.SaveChanges(); } catch (Exception ex) { throw ex; } }
/// <summary> /// 用于向 Location_Items EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToLocation_Items(Location_Item location_Item) { base.AddObject("Location_Items", location_Item); }
/// <summary> /// 创建新的 Location_Item 对象。 /// </summary> /// <param name="id">Id 属性的初始值。</param> /// <param name="address">Address 属性的初始值。</param> /// <param name="typeId">TypeId 属性的初始值。</param> /// <param name="trashId">TrashId 属性的初始值。</param> /// <param name="amount">Amount 属性的初始值。</param> /// <param name="itemName">ItemName 属性的初始值。</param> /// <param name="latitude">Latitude 属性的初始值。</param> /// <param name="longitude">Longitude 属性的初始值。</param> /// <param name="price">Price 属性的初始值。</param> public static Location_Item CreateLocation_Item(global::System.Guid id, global::System.String address, global::System.Int32 typeId, global::System.Int32 trashId, global::System.Decimal amount, global::System.String itemName, global::System.Decimal latitude, global::System.Decimal longitude, global::System.Decimal price) { Location_Item location_Item = new Location_Item(); location_Item.Id = id; location_Item.Address = address; location_Item.TypeId = typeId; location_Item.TrashId = trashId; location_Item.Amount = amount; location_Item.ItemName = itemName; location_Item.Latitude = latitude; location_Item.Longitude = longitude; location_Item.Price = price; return location_Item; }