Linq 2 SQL Store inherited classes - not mapped to tables in the database
- by user348672
Hi.
I'm trying to introduce the Linq2SQL technique into the project and have encountered the following issue:
I've created ORM classes based on the Northwind database. In some other application I create several classes derived from the Linq2SQL classes. I'm able to add such a class to EntitySet but the application fails to submit changes. Is there any way around this?
Sample code(MyClass is derived from the Order):
DataClasses1DataContext northwind = new DataClasses1DataContext();
Product chai = northwind.Products.Single(p => p.ProductName == "Chai");
Product tofu = northwind.Products.Single(p => p.ProductName == "Tofu");
Order myOrder = new Order();
myOrder.OrderDate = DateTime.Now;
myOrder.RequiredDate = DateTime.Now.AddDays(1);
myOrder.Freight = 34;
Order_Detail myItem1 = new Order_Detail();
myItem1.Product = chai;
myItem1.Quantity = 12345;
Order_Detail myItem2 = new Order_Detail();
myItem2.Product = tofu;
myItem2.Quantity = 3;
myOrder.Order_Details.Add(myItem1);
myOrder.Order_Details.Add(myItem2);
Customer myCustomer = northwind.Customers.Single(c => c.CompanyName == "B's Beverages");
MyClass newOrder = new MyClass();
newOrder.OrderDate = DateTime.Now;
newOrder.RequiredDate = DateTime.Now.AddDays(31);
newOrder.Freight = 35;
Order_Detail myItem3 = new Order_Detail();
myItem3.Product = tofu;
myItem3.Quantity = 3;
newOrder.Order_Details.Add(myItem3);
myCustomer.Orders.Add(myOrder);
myCustomer.Orders.Add(newOrder);
As I said I'm able to add the newOrder object but unable to submit into the database.