NHibernate, I can say this with Fetch <T>, but can I say that it remains <T>?

As soon as a question arises, I know that with NHinbernate I can specify a specific request Fetch(Func<T,bool>)and even FetchMany(). But what if I want to do the opposite?

For example, let's say we have a class.

class Employee {
  public virtual string Name { get; set; }
  public virtual Address Address { get; set; }
  public virtual double Salary { get; set; }
}

If you Employeelook at my profile, I would like to Address, and Salarydisplayed. But what if another employee is watching? It would seem more convenient to create one ASP.NET MVC View, but not specifically return data that should be hidden. So that..

if( // myself // ) {
   return employee = session.Query<Employee>()
       .Fetch(context => context.Address)
       .Take(1)
       .SingleOrDefault();
}
else
   return employee = session.Query<Employee>()
       .Deny(context => context.Address)
       .Deny(context => context.Salary)
       .Take(1)
       .SingleOrDefault();

Then my view may look like this.

@model Employee

<h2>@Model.Name</h2>
<h4>@Html.DisplayFor( model => model.Address )</h4>
<h4>@Model.Salary</h4>

I understand that this is not the best example in the universe, but is this possible? I have not found any methods that explicitly indicate that the object is not being returned, so far.

+3
1

, ASP.NET MVC: . , Employee, , Employee EmployeeViewModel. . , .

+3

All Articles