I have created a (dummy) database view, called; vContact, and a stored procedure returning the same types as the view (the view would be too complex if I should do what I need). When I invoke the stored procedure I get a ContactView object with the CompanyId filled but the Company object shows (when watched in Visual Studio):
A relationship multiplicity constraint violation occurred: An EntityReference can have no more than one related object, but the query returned more than one related object. This is a non-recoverable error.
I'm using a database-first approch... I think that I have to do some fluent configuration? I think that it's something about I'm using an "encapsulating" view class so the reversed objects are not of equal type ?
Here are my objects:
[Table("vContact")]
public class ContactView : Contact
{
// …
}
[Table("Contact")]
public class Contact
{
[Key]
public Guid Id { get; set; }
// …
[Required]
public int CompanyId { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection<Activity> Activities { get; set; }
}
[Table("Company")]
public class Company
{
[Key]
public int Id { get; set; }
// …
public virtual ICollection<Contact> Contacts { get; set; }
public virtual ICollection<Activity> Activities { get; set; }
}
[Table("Activity")]
public class Activity
{
[Key]
public Guid Id { get; set; }
// …
[Required]
public int CompanyId { get; set; }
public virtual Company Company { get; set; }
}
My goal is to get a ContactView object, with the filles Contacts and Activities, but the Company only have to contain the "basics" - not all the contacts and activities that refers to the company.
But the properties have to be there on the company object when querying the company for activities and activities using the vCompany view by another stored procedure.
PS. I got equivalent views and stored procedures for Contact and Activities