this is my user model or class
public int UserID { get; set; }
public string UserName { get; set; }
public string UserPassword { get; set; }
public int CompanyID { get; set; }
public int BranchID { get; set; }
public bool RecordState { get; set; }
public virtual Branch Branch { get; set; }
public virtual Company Company { get; set; }
and this is my company class
public int CompanyID { get; set; }
public string CompanyName { get; set; }
public string CompanyShortName { get; set; }
public string CompanyAddress { get; set; }
public string CompanyPhone { get; set; }
public string CompanyEmail { get; set; }
public string CompanyFax { get; set; }
public bool RecordState { get; set; }
public virtual List<Branch> Branches { get; set; }
public virtual List<Customer> Customers { get; set; }
public virtual List<Market> Markets { get; set; }
public virtual List<Seller> Sellers { get; set; }
public virtual List<User> Users { get; set; }
this my [WebMethod]
public User getUser(int id)
{
User user = db.Users
.Include(c => c.Company)
.Where(i => i.UserID == id)
.FirstOrDefault<User>();
Company company = db.Companies
.Where(i => i.CompanyID == user.CompanyID )
.FirstOrDefault<Company>();
company.Branches = null;
company.Customers = null;
company.Markets = null;
company.Sellers = null;
company.Branches = null;
company.Users = null;
user.Company = company;
return user;
}
My method is long beacuse I want to avoid circular reference but I think my steps is not good and it takes many steps I want to know i there any why that I can get the company inside user with one query and it should also return an object type user because ? i'm really sorry for my bad English