Jseb Jseb - 3 months ago 13
C# Question

How to fetch an attributes from my class with EF

I have 3 class, 2 are simple class and 1 combines the two of them.

public class Person:Base
{
public DateTime DOB { get; set; }
public string first { get; set; }
public string last { get; set; }
}

public class Roles:Base
{
public string Description { get; set; }
}

public class RolePerson:Base
{
public int pID { get; set; }
public virtual Person PersonID { get; set; }
public int rID { get; set; }
public virtual Roles RoleID { get; set; }
public int order { get; set; }
}


Now I have method that would select RolePerson witch would grab all member of pID with the id that i provide in the argument, and return the RoleID field.

this is how my method look like

public IEnumerable<Roles> PersonRoles(int personID)
{
return db.RolePerson.Where<RolePerson>((p) => p.pID == personID);
}


How can i say to return the role and not the roleperson.

Update:

My base class is as follow

public abstract class Base
{
public int ID { get; set; }
public Boolean isValid { get; set; }
public DateTime createdOn { get; set; }
public int createdID { get; set; }
public Person createdPerson { get; set; }
public DateTime updatedOn { get; set; }
public int updatedID { get; set; }
public Person updatedPerson { get; set; }
}

Answer

You can run a select statement in the end.

return d.RolePerson.Where(p => p.PId == personID).Select(r=> r.RoleID);