My Code for a controller:
public ViewResult Index(int? ProjectID)
{
var user = HttpContext.User;
User profile = db.Users.Where(d => d.Email == user.Identity.Name).Single();
var contracts = db.Contracts.Include(c => c.Project);
if (!user.IsInRole("Admin"))
{
contracts = contracts.Where(p => p.Project.Client == profile.Client );
}
if (ProjectID != null)
{
contracts = contracts.Where(u => u.ID == ProjectID);
}
return View(contracts.ToList());
}
This is suppose to pull up all of the contracts whose parent project has the same client fk as the user currently signed in unless they are an admin. This isn’t working.
I am getting the following error when the non-admin’s look at the page:
Unable to create a constant value of type
‘MembershipExt.Models.Client’. Only primitive types (‘such as Int32,
String, and Guid’) are supported in this context.
Do I need to use a second include or something?
i am guessing the problem is in the above line the right hand side of lambda needs to be of simple type that is
int32,stringetc but you are having a complex type i.e.p.Project.Client