提出问题提出问题
 

已答复Update reference

  • 2008年3月6日 22:56lubein 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    I have a LastModified relationship between SiteUser and GroupPost entities (1..*)

    I'm trying to update reference using code below

    using (myEntities ee = new myEntities())

    {

    GroupPost post = (from posts in ee.GroupPost.Include("SiteUser")
                                     where posts.PostID == id
                                     select posts).First<GroupPost>();

    SiteUser u = ee.SiteUser.First<SiteUser>(e => e.UserName == HttpContext.User.Identity.Name);

    post.SiteUser = u;               
             
         ee.SaveChanges();
    }



    which throws an exception

    A relationship is being added or deleted from relationship set 'SiteUserGroupPost'. Given cardinality constraints, a corresponding 'GroupPost' must also be added or deleted.

    How can I bind one existing entity object to another existing object?

答案

全部回复