IEditableCollectionView.AddNew() Throwing ArgumentNullException
In the c开发者_开发知识库ontext of Silverlight RIA using DomainContext and, the code as follows:
private void AddProductButton_Click(object sender, RoutedEventArgs e)
{
var target = (Web.LocatorProduct)((IEditableCollectionView)ProductSource.DataView).AddNew();
target.Locator = LocatorID;
target.Product = NewProduct.Text.ToUpper();
((IEditableCollectionView)ProductSource.DataView).CommitNew();
}
Is throwing ArgumentNullException in AddNew(), CreateIdentity() further up on the stack (a generated method) due to product being null. Product and LocatorID are, in combination, the primary key.
I'm guessing that EF is not allowing me to generate a new item without meeting database contraints? How does this make sense if I need to obtain a primary key from the user?
I have control over all tiers of the application, so suggestions on database design if needed are also welcomed.
Ok, problem solved. The reason I was using this interface was because I read about it in a forum. I failed to recognize that I could just as easily make use of DataView without the interface cast to achieve the result, DataView being a (possibly transient) view of what your data will look like after a commit, and more specifically, what it LOOKS like, literally, on the visual control. The code change is as follows:
var target = new Web.LocatorProduct()
{
Locator = LocatorID,
Product = NewProduct.Text.ToUpper()
};
ProductSource.DataView.Add(target);
Very simple.
精彩评论