Hi everyone, I receive the following error "sequence contains more than one element" when trying to populate my promotion table object. I know i recieve this error becuase my query returns multiple values as it should. Can anyone point me in the right direction as to how to delete multiple records besides looping(if possible with EF).
main proc:
TBLPROMOTIONCOLLECTION promotionCollectionInfo = null;
using (webStoreEntities webStoreContext = new webStoreEntities())
{
promotionCollectionInfo = WebStoreDelegates.selectPromotionCollection.Invoke (webStoreContext).ByPromoID(promotionId).ToList().SingleOrDefault();
if (promotionCollectionInfo != null)
{
webStoreContext.DeleteObject(promotionCollectionInfo);
webStoreContext.SaveChanges();
}
}
selectPromotionCollection Delegate:
public static Func<webStoreEntities, IQueryable<TBLPROMOTIONCOLLECTION>> selectPromotionCollection =
CompiledQuery.Compile<webStoreEntities, IQueryable<TBLPROMOTIONCOLLECTION>>(
(promotion) => from c in promotion.TBLPROMOTIONCOLLECTION
select c);
ByPromoID filter:
public static IQueryable<TBLPROMOTIONCOLLECTION> ByPromoID(this IQueryable<TBLPROMOTIONCOLLECTION> qry, int promotionID)
{
//Return the filtered IQueryable object
return from c in qry
where c.PROMOTION_ID == promotionID
select c;
}
FirstorDefault doesn't fix my problem since i am expecting multiples. Any help would be appreciated.
Thanks, Billy