Note that there are some explanatory texts on larger screens.

plurals
  1. POEntityType 'MyProfile' has no key defined. Define the key for this EntityType
    primarykey
    data
    text
    <p>I am not sure why I am getting this error message. I have a primary key defined in my sql database for it. Here is my code:</p> <pre><code>[HttpPost] public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email); if (createStatus == MembershipCreateStatus.Success) { FormsService.SignIn(model.UserName, false /* createPersistentCookie */); MembershipUser myObject = Membership.GetUser(); Guid UserID = (Guid)myObject.ProviderUserKey; MyProfile profile = new MyProfile(); profile.Address = model.Address; profile.City = model.City; profile.Zip = model.Zip; profile.State = model.State; profile.UserId = UserID; db.Profiles.Add(profile); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form ViewBag.PasswordLength = MembershipService.MinPasswordLength; return View(model); } </code></pre> <p>And this is my MyProfile Class:</p> <pre><code> namespace MatchGaming.Models { [Bind(Exclude = "ProfileId")] public class MyProfile { [ScaffoldColumn(false)] public int ProfileId { get; set; } public Guid UserId { get; set; } [DisplayName("Address")] public string Address { get; set; } [DisplayName("City")] public string City { get; set; } [DisplayName("Zip")] public string Zip { get; set; } [DisplayName("State")] public string State { get; set; } } } </code></pre> <p>I am not sure why I am getting this error: <code>EntityType 'MyProfile' has no key defined. Define the key for this EntityType.</code> when it tries to add to the database <code>db.Profiles.Add(profile);</code>. </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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