开发者

ASP.NET MVC Sample for foreign item collection editing

Does anyone know of any mvc samples that implement a one to many editing situation in a single or multiple views?

For开发者_JAVA技巧 example I'm looking for something that would show how to best implement a simple relationship of Order to OrderItem where OrderItem contains a Product reference and a Quantity. Sample models would be as follows:

public class Order     
{
   public int OrderID { get;set;}
   public string Name { get;set;}

   public ICollection<OrderItem> OrderItems { get;set;}
}

public class Product
{
   public int ProductID { get;set;}
   public string Name { get;set;}
}

public class OrderItem
{
   public int OrderItemID { get;set;}
   public Product Product { get;set;}
   public int Quantity { get;set;}
   public Order Order { get;set;}
}

I've looked at a lot of the samples out there and they are for simple CRUD operations without any navigation properties etc. Also, if possible I'd love to figure out how to edit an existing Order, adding, removing, changing OrderItem's without persisting to the database until the Save action on the Order is run.


I don't quite get your question. What is the problem you are trying to solve?

If you are looking for general ideas for working with MCV+EF, then look for repository pattern.

If I understand the editing without persisting to the database until Save action part, every time you run an action in your controller you will most likely open a new context do your changes and save changes. I don't see a scenario where you don't save after editing anything in your context, again a little more detail would help.


You're looking for:

Complex model binding to a list

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜