我遇到了一个问题,它搜索并尝试了所有我能找到的解决方案,但无济于事。我使用的整个过程中ASP.NET Mvc中的实体框架更新错误与相关实体
我有一个预定实体和userExtension实体 下同库和上下文是我的形象alt text http://i41.tinypic.com/25ulmgy.jpg
然后让我的形式收集从我的网页回来,创建一个新的预订
public ActionResult Create(FormCollection collection)
{
Booking toBooking = new Booking();
我然后做一些验证和财产分配,并找到相关的BidInstance toBooking.BidInstance = bid;
我已经确认并出价不为空。最后,我从当前的IPrincipal用户的用户扩展文件如下
UserExtension loggedInUser = m_BookingRepository.GetBookingCurrentUser(User);
toBooking.UserExtension = loggedInUser;
做getUserExtension的代码是:
public UserExtension GetBookingCurrentUser(IPrincipal currentUser)
{
var user = (from u in Context.aspnet_Users
.Include("UserExtension")
where u.UserName == currentUser.Identity.Name
select u).FirstOrDefault();
if (user != null)
{
var userextension = (from u in Context.UserExtension.Include("aspnet_Users") where u.aspnet_Users.UserId == user.UserId select u).FirstOrDefault();
return userextension;
}
else{
return null;
}
}
它返回userextension精和细分配给它。我最初使用aspnet_users但遇到此问题,所以试图将其更改为扩展实体。 只要我所说的:
Context.AddToBooking(booking);
Context.SaveChanges();
我得到下面的异常和IM完全如何解决它
实体在“FutureFlyersEntityModel.Booking”莫名其妙参加“FK_Booking_UserExtension”的关系。找到0个相关的“UserExtension”。预计会有'UserExtension'。
那么涉及到前端的最终误差是:
的关系“FutureFlyersModel.FK_Booking_BidInstance”元数据的信息无法被检索。确保已经在程序集中定义了关系的EdmRelationshipAttribute。 参数名:relationshipName ..
但两者的相关实体的预定实体设置通过thruogh
请帮助林在束手无策这个