I'm working on a project with an existing databse. Didn't really have any problems until now as I can't understand how I could possibly write this query.
I have two Entities:
Contactperson.cs
public class ContactPerson
{
public Guid ContactPersonID { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string City { get; set; }
public string ZIP { get; set; }
public string StreetAndNumber { get; set; }
public bool Active { get; set; }
}
ClientContactPerson.cs
public class ClientContactPerson
{
public Guid ClientID { get; set; }
public Guid ContactPersonID { get; set; }
public int? RelationshipID { get; set; }
public string Comment { get; set; }
public virtual Client { get; set; }
}
On Client.cs the only relation to ClientContactPerson is this:
public virtual ICollection<KlientKontaktperson> KlientKontaktperson { get; set; }
Now, what I need to query is, I pass the ClientID to the controller:
public JsonResult GetContactperson(Guid Id)
{
var ContactQuery = db.ClientContactPerson.Where(i => i.ClientID == Id).ToList();
var contactperson = Mapper.Map<IEnumerable<ContactpersonDto>>(contactpersonQuery);
return Json(kontaktperson, JsonRequestBehavior.AllowGet);
}
Now my JSON response looks like this:
{
"ClientContactPerson": "e5b05f3a-4fa5-4489-9d0b-118c3d51697d",
"LastName": null,
"FirstName": null,
"City": null,
"ZIP": null,
"StreetAndNumber": null,
"Active": false
}
Now I can't even use automapper (I guess) since I cannot navigate to say ContactPerson and map the fields to my ContactPersonDto.
I know I'm missing something here but I have 0 clue how I could deal with such columns. Probably will be running into the same problem as I progress with working on the databse.
Hope someone can lead me in the right direction on this one. Thanks
ContactPersonDtoobject?