Print Page | Close Window

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

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3794
Printed Date: 13-May-2026 at 1:02am


Topic: Error: During save of a many-to-many relationship "Sequence contains no matching element "
Posted By: Matt Foley
Subject: Error: During save of a many-to-many relationship "Sequence contains no matching element "
Date 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.



Replies:
Posted By: Matt Foley
Date 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);
}


Posted By: sbelini
Date 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.


Posted By: Matt Foley
Date 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!



Print Page | Close Window