This is my first question so be gentle 🙂
I want to be able to use method for generic types which will return me object for later use. I have tried the code below but it’s not complete.
I need this to call like this: City city = GetDataById(Id); Of course instead of city I need generic use.
Thanks and regards.
private T GetDataById(Guid Id)
{
T obj;
using (ISession session = Session.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
obj = session.Get<T>(Id);
tx.Commit();
}
return obj;
}
}
You never define T. You… need to.
And…
You’ll never be able to call it like that because the type argument cannot be inferred. You will need to supply it, i.e.,