I am developing crm database based application. i want to get number of salesorderdetails under salesorder entity using linq to sql.
i am using subselect query for this. salesorder entity has new_sefer field. My query is
(from d in context.SalesOrderDetailSet
where context.SalesOrderSet.Where(s => s.new_Sefer.Id == Id)
.Select(i => i.SalesOrderId).Contains(d.SalesOrderId.Id)
select d).Count();
it throws below exception. I have also question about subselect queries
how can i write this sql query using linq to sql
select count(*) from salesorderdetail
where salesorderId in (select salesorderId from salesorder
where new_sefer = '750FEB6F-F742-E311-8F56-000C29F3049E')
"Invalid 'where' condition. An entity member is invoking an invalid property or method."
at Microsoft.Xrm.Sdk.Linq.QueryProvider.ThrowException(Exception exception)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.FindValidEntityExpression(Expression exp, String operation)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.FindValidEntityExpression(Expression exp, String operation)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhereMethodCall(MethodCallExpression mce, FilterExpressionWrapper parentFilter, Func2 getFilter, BinaryExpression parent, Boolean negate)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhereBoolean(String parameterName, Expression exp, FilterExpressionWrapper parentFilter, Func
2 getFilter, List1 linkLookups, BinaryExpression parent, Boolean negate)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhere(QueryExpression qe, String parameterName, Expression exp, List
1 linkLookups)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.GetQueryExpression(Expression expression, Boolean& throwIfSequenceIsEmpty, Boolean& throwIfSequenceNotSingle, Projection& projection, NavigationSource& source, List1& linkLookups)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](Expression expression)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable
1 source)
at Xrm.SalesOrderDetailOperations.SelectSalesOrderDetailBySeferId(XrmServiceContext context, Guid Id) in C:\SVN\Customers\Burulas\FlyDBOperations\FlyDBOperations\SalesOrderDetailOperations.cs:line 26
at FlyDBOperationsTest.SalesOrderDetailOperationsSalesOrderDetailOperationsTest.SelectSalesOrderDetailBySeferIdSelectSalesOrderDetailBySeferIdTest() in C:\SVN\Customers\Burulas\FlyDBOperations\FlyDBOperationsTest\SalesOrderDetailOperationsSalesOrderDetailOperationsTest.cs:line 82