I’m designing the data model for an app with the LINQ to SQL (O/R) designer and wonder: is it possible to have (many) classes implement an interface or base class and store the implemented fields’ values in the DB?
Most if not all of my classes need common fields to be stored that describe metadata about the object, such as when and by whom the object was created, whether the object was deleted and when it was last modified… The values for these fields would ideally just go into columns on the implementing classes’ tables in the database.
I know of the option to specify a global base class or interface in the .dbml file, but that’s not very elegant since I will have some L2S classes that don’t implement the interface.
I know that this is easy to do with something like NHibernate. I’d just like to see if there is a way to do this with LINQ to SQL in an elegant way.
Any pointers?
Yes, it is possible. Just add separate code files with partial counterparts of your classes and implement your interfaces there.