Classes to Entities; Like-class inheritence problems


Beyond work, some friends and I are trying to build a game of sorts; The way we structure some of it works pretty well for a normal object oriented approach, but as most developers will attest this does not always translate itself well into a database persistent approach.

This is not the absolute layout of what we have, it is just a sample model given for sake of representation.

The whole project is being done in C# 4.0, and we have every intention of using Entity Framework 4.0 (unless Fluent nHibernate can really offer us something we outright cannot do in EF).

One of the problems we keep running across is inheriting things in database models. Using the Entity Framework designer, I <strong>can</strong> draw the same code I have below; but I'm sure it is pretty obvious that it doesn't work like it is expected to.

To clarify a little bit; 'Items' have bonuses, which can be of anything. Therefore, every part of the game must derive from something similar so that no matter what is 'changed' it is all at a basic enough level to be hooked into. Sounds fairly simple and straightforward, right?

So then, we inherit everything that pertains to the game from 'Unit'. Weights, Measures, Random (think like dice, maybe?), and there will be other such entities. Some of them are similar, but in code they will each react differently.

We're having a really big problem with abstracting this kind of thing into a database model. Without 'Enum' support, it is proving difficult to translate into multiple tables that still share a common listing. One solution we've depicted is to use a 'key ring' type approach, where everything that attaches to a character is stored on a 'Ring' with a 'Key', where each Key has a Value that represents a type. This works functionally but we've discovered it becomes very sluggish and performs poorly. We also dislike this approach because it begins to feel as if everything is 'dumped' into one class; which makes management and logical structure difficult to adhere to.

I was hoping someone else might have some ideas on what I could do with this problem. It's really driving me up the wall; To <strong>summarize</strong>; the goal is to build a type (Unit) that can be used as a base type (Table per Type) for generic <strong>reference</strong> across a relatively global scope, without having to dump everything into a single collection. I can use an Interface to determine actual <em>behavior</em> so that isn't too big of an issue.

<a href="http://img171.imageshack.us/img171/5153/modelg.png" rel="nofollow">alt text http://img171.imageshack.us/img171/5153/modelg.png</a>

This is 'roughly' the same idea expressed in the Entity Framework.

<a href="http://img684.imageshack.us/img684/6454/entities.png" rel="nofollow">alt text http://img684.imageshack.us/img684/6454/entities.png</a>


Have you tried a Table per Concrete Type mapping for Unit? i.e. using the Id field to link the Measure, Weights and Random tables? (each has an Id column and they are related through this.)

I think the relationship you show between Sheet and Measure is going to be problematic in a Table per class mapping. Sheet can't map to just Measures if the type type of unit 'measure' is determined by a discriminator column in Units. With TPCT you can map Sheet to Measures successfully because it can use the Id to 'get back' to the Units table.

Unfortunately there's very little by way of examples for TPCT: sometimes it seems to take a few iterations of {edit model, export database, make changes in SSMS, import database} ... to get it right.


  • SuperFloppyFormatter returning FAT32 for anything over 512 MB?
  • uploading video to Facebook error 5
  • Why does the Java compiler complain about a local variable not having been initialized here?
  • COM Interop & Outlook - Make Outlook Visible?
  • How redirection internally works in unix
  • KnockOutJS - getting an 'undefined' value, not sure why
  • Carriage return required when printing to the console in Windows?
  • Different outcomes when using tf.Variable() and tf.get_variable()
  • Dropdown menu with the dropdown-menu-right class does not align to the right
  • All shortest paths for weighted graphs with networkx?
  • Looking for datastructure that maintains a size & purges older elements in the process
  • How to provide hyperlink in email pointing to a specific method inside gwt app (but not main page)
  • How to make a matlab legend recognize multiple scatter plots?
  • Is it possible to disable jQuery's mobile responsive design?
  • Process.PrivateMemorySize64 returning committed memory instead of private
  • How to model a mixture of finite components from different parametric families with JAGS?
  • Ant: fileset “dir” attribute with a runtime expanded full path
  • Fixed Background Works in Chrome but Not Firefox?
  • Error in GGally: Error in unit(tic_pos.c, “mm”) : 'x' and 'units' must have leng
  • How can I see a list of all files that are different between two Hg repositories?
  • Receive mouse move even cursor is outside control
  • Why isn't my “Fizz Buzz” test in R working?
  • Python PIL to extract number from image
  • Request response issues in biztalk
  • CodeIgniter URI Parameter is partially bypassing an “if” statement
  • opencv display image without x server
  • Git describe fails to return most recent annotated tag
  • Approximate Order-Preserving Huffman Code
  • Overlapping controls in Windows XP
  • calculate gradient output for Theta update rule
  • Unable to install Git-core+svn by MacPorts
  • Django simple Captcha “No module named fields” error
  • Could not find rake using whenever rails
  • Asynchronous UI Testing in Xcode With Swift
  • Illegal mix of collations for operation for date/time comparison
  • Can Jackson SerializationFeature be overridden per field or class?
  • Redux, normalised entities and lodash merge
  • Android Studio and gradle
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How to get NHibernate ISession to cache entity not retrieved by primary key