New Posts New Posts RSS Feed: Error: During save of a many-to-many relationship "Sequence contains no matching element "
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Error: During save of a many-to-many relationship "Sequence contains no matching element "

 Post Reply Post Reply
Author
Matt Foley View Drop Down
Newbie
Newbie


Joined: 21-Jul-2011
Location: Birmingham, AL
Posts: 9
Post Options Post Options   Quote Matt Foley Quote  Post ReplyReply Direct Link To This Post Topic: Error: During save of a many-to-many relationship "Sequence contains no matching element "
    Posted: 13-Nov-2012 at 11:29am
I have a many-to-many relationship defined with a join table that uses Foreign Key association, and there is no payload.


When I add a secondary object to the first object's navigation property, all is fine (both navigation property RelatedEntityLists are populated as they should be), until I try to save.

System.InvalidOperationException: Sequence contains no matching element
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
   at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.ProcessManyToMany(List`1 entities)
   at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.ProcessSaves(IEnumerable`1 groupsByType)
   at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.SaveWithinContext()
   at IdeaBlade.EntityModel.Edm.EdmSaveExecutor.Save(DataSourceResolver dataSourceResolver, IDataSourceKey dsKey, SaveWorkState workState)

They only thing I'm doing differently here is I'm doing a linq query (based on information outside of the model) to determine which secondary object to add to the collection.
Back to Top
Matt Foley View Drop Down
Newbie
Newbie


Joined: 21-Jul-2011
Location: Birmingham, AL
Posts: 9
Post Options Post Options   Quote Matt Foley Quote  Post ReplyReply Direct Link To This Post Posted: 13-Nov-2012 at 11:31am
var q = from r in CurrentUser.Rights
        join d in ((Scheduler.SchedulerEntities)result.EntityAspect.EntityManager).Divisions on r.RightName equals d.Name
        select d;

foreach (Division division in q)
{
    if (division != null) result.Divisions.Add(division);
}

Edited by Matt Foley - 13-Nov-2012 at 11:32am
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 13-Nov-2012 at 2:09pm
Hi Matt,
 
I'm confused as to why the query would influence the save.
 
Can you please provide a simple solution reproducing the issue?
 
Thanks,
   sbelini.
Back to Top
Matt Foley View Drop Down
Newbie
Newbie


Joined: 21-Jul-2011
Location: Birmingham, AL
Posts: 9
Post Options Post Options   Quote Matt Foley Quote  Post ReplyReply Direct Link To This Post Posted: 30-Nov-2012 at 8:55am
Our project is large and reducing it to a manageable size is quite an undertaking.  We are a small team and under a crunch at the moment getting a release out; in the meantime I have worked around this issue.  After the release I will have time to work this out.

Thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down