none
Many-to-Many relation. Problem with insert (and Self-tracking entity POCO) RRS feed

  • Question

  • Hello,

    I have difficulty to figure out with inserting in a many-to-many relation. I have 3 physical tables :

    Options, Functions and an association table FunctionsOptions.

    I mapped the association between Options and Functions through FunctionsOptions in my model. So I just have 2 entities (Options and Functions).

    Now I'd like to affect some Functions to an Option like this : 

    public AddFonctionsOption(List<Functions> p_func, Options opt)
            {
    using (Session oSession = new Session())
                {
                               
                    foreach (Fonctions f in p_func)
                    {
                        opt.Fonctions.Add(f);
                    }
    
                    oSession.Context().Options.ApplyChanges(opt);
                    oSession.Context().SaveChanges()
                }
    


    When I call this method, entity framwork try to insert into Functions table, instead the FunctionsOptions table.

    The option I'am passing in parameter is marked as Unchanged and every Functions in my list are marked as Unchanged too.

    So, I don't understand why EF is trying to insert into Functions.

     

    Please help

     

    zer

     

     

     

     

    Friday, September 30, 2011 10:01 AM

Answers