Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: Implementing a Mixin Pattern in EF

$
0
0

I'm new to .NET and EF, in particular, coming from a Ruby/Python background. In those two languages it's common to create mixins, essentially abstract classes, that other classes will inherit properties and methods from. The mixin itself is not instantiated, and in the case of a model, no database is created for it. Instead, all the fields on the mixin are added to the table for the subclass and every practical way, the subclassed model behaves as though those fields were just added right to its code.

For example, lets say I had both a Person model and a Business model. Both have an address, so they both would need fields like street, city, zip, etc. However, instead of adding these fields directly on the model, I might instead create an Address mixin, Person and Business would then inherit Address. However, Address would have no table in the database, and if you looked at the Person and Business tables, there would be no difference than if you had literally defined the fields on the class.

Two candidates in EF seem close to what I'm looking for: Complex Types and TPC (Table per Concrete Type). And just to make things more difficult, I would prefer my mixin to be able to include navigation properties, which I think rules out Complex Types from what I've read.

Basically, I'm just trying to figure out what the best approach here is: which of these two paths should I follow, or is there some other way I'm not aware of that would be more appropriate?


Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>