Scenario:
Trying to call the .AttachAll method on a table in my LinqToSql DataContext object.
Here’s the relevant simplified snippet:
public void Update(Customer cust){
MyDataContext db = new MyDataContext();
db.CustomerInvoices.AttachAll(cust.Invoices); //exception raised here!
db.Customer.Attach(cust);
}
Exception raised by the Compiler:
The type arguments for method
‘System.Data.Linq.Table(Invoices).AttachAll(TSubEntity)(System.Collections.Generic.IEnumerable(TSubEntity))’
cannot be inferred from the usage. Try
specifying the type arguments
explicitly.
Question: What is the proper way to cast the collection properly? Any other solutions besides a cast?
Tf cust.Invoices already refers to instances of the CustomerInvoices table, just doing
db.Customers.Attach(cust); db.Update(); should be all you need to do.
If CustomerInvoices is a different type from Customer.Invoice, you’ll probably need to iterate through the collection, and cast each one.