Hi to everyone,
FIrst and foremost, I'm a newbie of NHibernate and Linq to NHibernate.
I have an User model class defined as follows:
public class User : IAggregateRoot
{
public virtual int Id { get; private set; }
public virtual string Login { get; set; }
public virtual string Password { get; set; }
public virtual IList<Role> Roles { get; set; }
public User()
{
Roles = new List<Role>();
}
public virtual Role GetRole(string name)
{
return Roles.FirstOrDefault(r => r.Name.ToString() ==
name);
}
public virtual Boolean IsAllowedTo(string path)
{
if (IsAdmin())
return true;
return Roles.FirstOrDefault(r =>
r.Privileges.FirstOrDefault(p => p.Path == path) != null) != null;
}
public virtual Boolean IsAdmin()
{
return (GetRole(DefaultRoleNames.Admin.ToString()) !=
null);
}
In my application the usual CRUD operations work flawlessly. Things
are not so good
when looking through the User's collection for administrators.
I used the following code to accomplish the lookup:
var results = from user in user_rep where user.IsAdmin() == true
select user;
And what I get in return is the whole User's collection, just like the
"Where" clause wasn't there.
If I write:
var results = from user in user_rep where user.Login == "test" select
user;
The "Where" filter gets applied correctly and I get returned a
properly filtered collection.
It looks like the "Where" clause doesn't like using User's methods,
but only properties.
What's that I'm doing the wrong way?
Thanks in advance for your help.
Regards,
Carmine
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---