开发者

Choosing a schema for SQL lookup table in the context of LINQ to SQL: sql_variant or multiple fields

开发者 https://www.devze.com 2023-01-21 05:12 出处:网络
I have a question similar to this but in the context of L2S. I want to create a lookup table to store values that could be one of several possible datatypes. As suggested in the referenced question, I

I have a question similar to this but in the context of L2S. I want to create a lookup table to store values that could be one of several possible datatypes. As suggested in the referenced question, I could use sql_variant datatype. However, L2S maps sql_variant to Object, which is suboptimal. I'm guessing it's possible to get at the table metadata to find out the exact type, but I expect that would be too messy. Has anyone tried it?

Another possibility is to split the data across multiple tables, each containing one strongly-typed field, and a master table that would contain the discriminator. But, here I run into another problem: L2S only supports one type of inheritance: Table per Class Hierarchy. So, naturally, my next thought was to put all the value columns and the discriminator in one table. This way I could have an abstract parent class and several inheriting members. The columns would have to be called something like ValueInt, ValueDec, etc. although in the ORM I can rename them all Value. So, that seems like an OK solution but still slightly awkward: all the NULL's in the table for one. Anyone with better thoughts?

P.S. As an aside, all the lookup values are currently stored as applicationSettings in the config fi开发者_如何学JAVAle, which does provide strong-typing, but there are other issues with it.


I finally got around to documenting the solution that I ended up implementing. The article can be found here: http://www.codeproject.com/KB/vb/custom-settings-provider.aspx Hopefully this proves helpful to someone.

0

精彩评论

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