This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, Consider three entities, namely Workspace, Item and Document. Document inherits from Item and Workspace has a one to many relationship with Item. Each user has a Workspace with a name "MyName". Users may also have other Workspaces with other names. My aim is to delete all documents in the "MyName" workspace, for which the condition on the document is true. For example, I may look at the documents' relationship to other entities and if none exist delete them.
var workspaces = unitOfWork.Query<Workspace>().Where(w => w.Name == "MyName"); foreach (var document in workspaces.SelectMany(w => w.Items.OfType<Document>())) { // remove the document if a condition is met }
However, if there are no workspaces with the name "MyName", then the following exception is thrown in the foreach. See below. Any ideas? Werner
System.ArgumentOutOfRangeException occurred Message=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Source=mscorlib ParamName=index StackTrace: at System.SZArrayHelper.get_Item[T](Int32 index) at Mindscape.LightSpeed.Linq.Sqo.SelectMany.DeriveBackReferencePath(Type parentType, Type childType, Expression expression, Expression projectorToIgnore) at Mindscape.LightSpeed.Linq.Sqo.SelectMany.DeriveBackReferencePath(Type parentType, Type childType, Expression expression, Expression projectorToIgnore) at Mindscape.LightSpeed.Linq.Sqo.SelectMany.DeriveBackReferencePath(Type parentType, Type childType, Expression expression, Expression projectorToIgnore) at Mindscape.LightSpeed.Linq.Sqo.SelectMany.EvaluateSingleArgument(ExpressionVisitor visitor, MethodCallExpression expression) at Mindscape.LightSpeed.Linq.Sqo.SelectMany.Evaluate(ExpressionVisitor visitor, MethodCallExpression expression) at Mindscape.LightSpeed.Linq.Plan.LinqQueryBuilder.VisitMethodCall(MethodCallExpression exp) at Mindscape.LightSpeed.Linq.Plan.LinqQueryBuilder.Visit(Expression exp) at Mindscape.LightSpeed.Linq.Plan.LinqQueryBuilder.Build(Expression translation, LinqQueryProvider provider) at Mindscape.LightSpeed.Linq.LinqQueryProvider.GetExecutionPlan(Expression expression) at Mindscape.LightSpeed.Linq.LinqQueryProvider.Execute(Expression expression) at Mindscape.LightSpeed.Linq.LinqQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) at Mindscape.LightSpeed.Linq.LinqQuery`1.GetEnumerator() at Workshare.Cloud.Jobs.DeleteOrphanDocumentsJob.Execute(JobExecutionContext context) in S:\Cloud\src\Cloud\Jobs\DeleteOrphanDocumentsJob.cs:line 45
|
|
|
Thanks for letting us know about this -- we will investigate. In the meantime the following workaround works for us: var ds = (from w in UnitOfWork.Workspaces where Kind is the discriminator attribute and DocumentKind is the discriminator value for the Document class. We'll try to get you a fix for the OfType<> version and extension method syntax in the near future. |
|