作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我不确定为什么会收到此错误消息。我在我的 sql 数据库中为其定义了一个主键。这是我的代码:
[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);
}
这是我的 MyProfile 类:
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; }
}
}
我不确定为什么会收到此错误:EntityType 'MyProfile' 没有定义键。定义此 EntityType 的键。
当它尝试添加到数据库 db.Profiles.Add(profile);
时。
最佳答案
哪个领域是你的关键?无论它是什么 - ProfileId 或 UserId - 要么将名称更改为 MyProfileId 或 Id,要么在其上放置一个 [Key] 属性。
关于c# - EntityType 'MyProfile' 没有定义键。为此 EntityType 定义键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5306947/
事情是这样发生的;DoesNotExist 在/post/naver/ 我现在收到这个错误,因为我在这一行的末尾添加了 id,profile = MyProfile.objects.get(user=
我不确定为什么会收到此错误消息。我在我的 sql 数据库中为其定义了一个主键。这是我的代码: [HttpPost] public ActionResult Register(RegisterM
您好,我知道这里有两个问题。一个是 SimpleLazyObject 问题,我可以用一种有点骇人听闻的方式解决它。另一个是“Comment.user”必须是一个“MyProfile”实例,我不知道如何
我是一名优秀的程序员,十分优秀!