0

I would like to use NHibernate to query a database with different objects. I have a string and depending on what that string is then I would like to return an object and query the db using that object. However, I am not sure what the best design of this would be.

Simple logic:

public object CheckString(string s){
    if(s == "A")
        return objA;
    else if(s == "B")
        return objB;
}

public void main(){
    var obj = CheckString("A");
    session.CreateCriteria<obj>().List<obj>();
}
TheProgrammer
  • 1,314
  • 5
  • 22
  • 44

1 Answers1

1

You can use this overload ICriteria CreateCriteria(string entityName):

public string CheckString(string s){
    if(s == "A")
        return "EntityA";//entity name from the database
    else if(s == "B")
        return "EntityB";//entity name from the database
}

public void main(){
    string entityName = CheckString("A");
    session.CreateCriteria(entityName).List<T>();
}
Roman Koliada
  • 4,286
  • 2
  • 30
  • 59