Note that there are some explanatory texts on larger screens.

plurals
  1. POUse MVC 3 and Entity Framework, how do I map a different instance of the same class to 3 different collection properties?
    primarykey
    data
    text
    <p>So I created the following related Classes and I'm trying to do Code-First approach. I want the Quote class to reference 3 instances of the User class by 3 different navigable property names, but when I do DBInitializer to populate and create the DB, the Quote table has 6 columns instead of the expected 3 columns, of which 3 are always null. The navigable properties point to those 3 null columns, so whenever I point to Quote.Manager or one of the other 3 properties, it returns null instead of the actual manager. How can I fix this?</p> <p>Quote Class (I left a little off, but you get the point):</p> <pre><code>using System.Web; using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace QuoteManager.Models { public class Quote { public int QuoteID { get; set; } public virtual int StateID { get; set; } public virtual State State { get; set; } public virtual int CreatorID { get; set; } public virtual User Creator { get; set; } public virtual int AgentID { get; set; } public virtual User Agent { get; set; } public virtual int ManagerID { get; set; } public virtual User Manager { get; set; } } } </code></pre> <p>User class:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace QuoteManager.Models { public class User { public User() { this.Quotes = new HashSet&lt;Quote&gt;(); this.CreatedQuotes = new HashSet&lt;Quote&gt;(); this.ManagedQuotes = new HashSet&lt;Quote&gt;(); } public int UserID { get; set; } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } public virtual string Phone { get; set; } public virtual string Email { get; set; } public virtual ICollection&lt;Quote&gt; Quotes { get; set; } public virtual ICollection&lt;Quote&gt; CreatedQuotes { get; set; } public virtual ICollection&lt;Quote&gt; ManagedQuotes { get; set; } public virtual ICollection&lt;Note&gt; Notes { get; set; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload