Note that there are some explanatory texts on larger screens.

plurals
  1. POORM with entity classes and domain interfaces/classes
    primarykey
    data
    text
    <p>I'm trying to decide how to handle domain-level classes and interfaces with respect to objects populated via ORM (NHibernate in this case). I've mocked up a very simple scenario that helps to illustrate my current situation.</p> <pre><code>public interface ICar { public bool PassesEmisionStandards(string state); public int Horsepower { get; set; } public string Model { get; set; } } public class CarFromDB { public int Horsepower { get; set; } public string Model { get; set; } } public class ModelT : CarFromDB, ICar { public bool PassesEmissionStandards(string state) { return false; } public override string ToString() { return Model + " with " + Horsepower + " ponies"; } } </code></pre> <p>In this case, CarFromDB is the class that's got the mapping via NHibernate to my database. ICar is the interface that my UI/Controller code is handling. ModelT is one of the classes that have instances passed to the UI.</p> <p>In my actual domain, the PassesEmissionStandards is a complicated method that differs significantly among the different derived classes, and the CarFromDB class has a dozen simple properties along with references to other classes, both singly and in lists. This information is all used in the PassesEmissionStandards equivalent.</p> <p>I'm confused about the best way to end up with my derived classes decorated with the interface when I start with a populated base class from the ORM. The ideas I've come up with to try to handle this are:</p> <ol> <li>Decorate CarFromDB with ICar and try to come up with a clean way to implement the extensive PassesEmissionStandards method within it or by calling out to other classes for help</li> <li>Use AutoMapper or the equivalent + a factory to transform my base class objects into derived class objects</li> <li>Since the derived class type can be identified from a property in the base class, mapp my derived classes for NHibernate and find some way to hook into NHibernate to instruct it which mapped derived class to use.</li> </ol> <p>I feel like this must be a very common issue, but I searched around SO and other places without finding any solid guidelines. Please note: I'm relatively new to ORM and domain modelling and very new to NHibernate. Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload