發問發問
 

已答覆Update reference

  • Thursday, 6 March, 2008 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?

解答

所有回覆