can LINQ to SQL support single table inheritance?
I would like to design a generic Product table
for my POS system which it able to handle multiple typ开发者_如何学Goes of details e.g. brands, category, types (either is service or product) and other mores or any others things which I'm not yet aware of, from different businesses.
I have searched through Google and it seems that the best methods for this design is using the Single Table Inheritance
link.
Is the statement above correct? If yes, could LINQ to SQL handle the Single table inheritance approach? I would be appreciated if you can provide me some samples as i felt tired of modifying and adding tables for different customer requirement.
The "Single Table Inheritance" model is the only one supported by LINQ to SQL. In this model, you set a discriminator column (type) and indicate which object type to create based in the value in of the discriminator. Each instance type can have different field properties. Columns that aren't used by all types need to be set as nullable so that the null values are used when the other columns are inserted for a given type.
This being said, I'm not sure that this is the model that you want from your statement that you are "tired of modifying and adding tables for different customer requirement." The single table approach requires that you not only add the necessary additional columns to your tables for new types, but also generate new classes and compile your application to allow for these new requirements.
You may want to look into one of the key-value pair/NoSql document database approaches (http://en.wikipedia.org/wiki/Key-value_store#Key-value_store). With the key-value model , you have a separate row for each property of your object where the row consists of the objectId, propertyName and Value. This data structure allows you to have any shape without having to change your database schema. Unfortunately, there isn't a built-in mechanism for taking the flexible data models and mapping them to flattened objects in LINQ. You can build this with dynamic types in .NET 4 if you want. Adding UI and business logic is another task.
精彩评论