I am attempting to decide how to deal with domain-level classes and connects regarding objects populated via ORM (NHibernate within this situation). I have mocked up a simple scenario that can help as one example of my unique circumstances.

public interface ICar

condition)

    public int Horsepower 

    public string Model 



public class CarFromDB



    public string Model 



public class ModelT : CarFromDB, ICar

condition)

    

    public override string ToString()

    



Within this situation, CarFromDB may be the class that has the mapping via NHibernate to my database. ICar may be the interface that my UI/Controller code is handling. ModelT is among the classes which have instances passed towards the UI.

During my actual domain, the PassesEmissionStandards is really a complicated method that differs considerably one of the different derived classes, and also the CarFromDB class includes a dozen simple qualities together with references with other classes, both singly as well as in lists. This post is all utilized in the PassesEmissionStandards equivalent.

I am unclear about the easiest method to finish track of my derived classes decorated using the interface after i begin with a populated base class in the ORM. The minds I have develop to try and handle this are:

  1. Decorate CarFromDB with ICar and then try to develop a clean method to implement the extensive PassesEmissionStandards method there or by calling to other classes for help
  2. Use AutoMapper or even the equivalent + a factory to change my base class objects into derived class objects
  3. Because the derived class type could be recognized from the property within the base class, mapp my derived classes for NHibernate and discover a way to hook into NHibernate to teach it which planned derived class to make use of.

I seem like this should be one such problem, however i looked around SO along with other places without coming up with any solid recommendations. Please be aware: I am relatively recent to ORM and domain modelling and incredibly a new comer to NHibernate. Any assistance is appreciated.

I do not believe that I realize your condition, why canĀ“t you utilize:

public interface ICar

condition)

    public int Horsepower 

    public string Model 



public abstract class CarBase : ICar



    public string Model 

    public abstract bool PassesEmisionStandards(string condition)



Or maybe CarBase can be used for those derived classes too, you might like to use strategy pattern

public interface IEmissionCalculator



public CarBase : ICar



    public bool PassesEmisionStandards(string condition)

    information

        var ctx = new IEmissionCalculatorContext 

        return _calculator.Check(ctx)

    



You should use exactly the same DB-class, but assign different emission caluclations depending of the kind of vehicle.

In the event that does not work either, I'd use automapper.