Note that there are some explanatory texts on larger screens.

plurals
  1. POSeeding Membership with custom data Entity framework
    primarykey
    data
    text
    <p>I have the fallowing Models</p> <pre><code>namespace Prometheus.Models { [Table("People")] public class Person : IPerson { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Name { get { return FirstName + " " + LastName; } set{} } public string Email { get; set; } public DateTime? LastModified { get; set; } } } </code></pre> <p>And one that inherits it</p> <pre><code>namespace Prometheus.Models { [Table("UserProfile")] public class UserProfile : Person { public string UserName { get; set; } public string CNP { get; set; } public virtual Faculty Faculty { get; set; } public bool? IsUSAMV { get; set; } public virtual ICollection&lt;Result&gt; Results { get; set; } public virtual ICollection&lt;Project&gt; Projects { get; set; } } } </code></pre> <p>And the seed method</p> <pre><code>private void AddUser(string user, string password, SimpleMembershipProvider membership) { if (membership.GetUser(user, false) == null) { WebSecurity.CreateUserAndAccount(user, password, new { CNP = "1890531111111", IsUSAMV = true, }); } } </code></pre> <p>When i try to run the seed method without UserProfile extending Person everything is ok, but when it extends it i keep getting the fallowing error.</p> <pre><code>The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.UserProfile_dbo.People_Id". The conflict occurred in database "PrometheusDb", table "dbo.People", column 'Id'. The statement has been terminated. </code></pre> <p>Any help would be greatly appreciated thanks.</p> <p>I tried updateing my function to </p> <pre><code>private void AddUser(string firstName,string lastName, string password, SimpleMembershipProvider membership) { var user = firstName + "." + lastName; if (membership.GetUser(user, false) == null) { var profile = new UserProfile() { Email = "test@email.com", FirstName = firstName, LastName = lastName }; _context.Users.Add(profile); _context.SaveChanges(); WebSecurity.CreateAccount(user, password); } } </code></pre> <p>But now i get: - <strong>An error occurred while updating the entries. See the inner exception for details. System.Data.SqlClient.SqlException: Cannot insert explicit value for identity column in table 'UserProfile' when IDENTITY_INSERT is set to OFF.</strong></p>
    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