SteveG wrote:
First off - fantastic work.
1. I saw above on how to load a single entity, ie:
User justAddedUser = session.Load<User>(newUser.Id);
2. What is the correct format to load all users?
I tried this:
List<User> users = session.CreateCriteria(typeof(User)).List<User>();
but it was wanting a List instead of an List<User> from the CreateCriteria
I ended up using:
List<User> users = (List<User>)session.CreateCriteria(typeof(User)).List<User>();
This worked, but it seems to be a bit verbose - is there a better way to handle this?
Thanks!
Steve... Good thing we're working on similar domain objects ;-) Here's my code:
public static User Get(int id)
{
return DbSessionContext.Current.Session.Load<User>(id);
}
public static IList<User> List()
{
return DbSessionContext.Current.Session.CreateCriteria(typeof(User)).List<User>();
}
The issue with your first attempt is that it wants to return an IList and not a List. I guess, depending on the problem at hand, returning an IList is generally going to be an acceptable approach... .saves you from explicit casting too.