Guys,
I've got this problem that I searched almost everywhere (maybe I don't know the right keyword for it.) I need your help!
The relationship is quite simple, I have two Activerecord Domain: Team and User, and they have HasAndBelongsToMany relationship to each other.
My requirement now is to query the count of Users which has Team.Id = 4 and query the list of Users which has Team.Id = 4. So I am doing something like:
DetachedCriteria c = DetachedCriteria.For<Models.User>()
.AddOrder(Order.Desc("RegisterTime"))
.CreateAlias("Teams", "teams")
.Add(Expression.Eq("teams.Id", 4));
int count = ActiveRecordMediator<Models.User>.Count(c);
IList<Models.User> users = Models.User.FindAll(c);
Count is correctly retrieved, but the for the List query, I get exception:
Exception Details: System.InvalidCastException: At least one element in the source array could not be cast down to the destination array type.
If I use them separately. They are both correct. But when I use them one after another. There comes the exception. It's like DetachedCriteria shall not be used closely in two queries. Why is that?
What's the correct way to do it?
Need your help!