I have been looking everywhere and can not seem to solve this. I have the following linq to data entities that sometime returns an empty set. But I can not seem to test for the empty set?
IEnumerable<string> xrefLineItems = from xref in db.wysLkupItemCrossRefs
where xref.EndPointCustID == inCustID
select xref.BuyersItemNo;
Everytime I try this it evaluates to false whether or not there are entries in the Result set?
if (xrefLineItems == Enumerable.Empty<string>())
{ }
If I try to use xrefLineItems.Any() I get the follow exception
The method 'First' can only be used as a final query operation. Consider using the method 'FirstOrDefault' in this instance instead.
cheers bob
Here is the stack trace
Line 146:
Line 147: bool isEmpty;
Line 148: if (xrefLineItems.Any())
Line 149: {
Line 150: isEmpty = true;
Source File: H:\DirectEDI\MVC_EDI\MVC_EDI\MVC_EDI\Controllers\DirectEDIController.cs Line: 148
Stack Trace:
[NotSupportedException: The method 'First' can only be used as a final query operation. Consider using the method 'FirstOrDefault' in this instance instead.]
System.Data.Objects.ELinq.FirstTranslator.TranslateUnary(ExpressionConverter parent, DbExpression operand, MethodCallExpression call) +100
System.Data.Objects.ELinq.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) +81
System.Data.Objects.ELinq.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod) +14
System.Data.Objects.ELinq.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) +102
System.Data.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq) +54
System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +110
System.Data.Objects.ELinq.EqualsTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression linq) +70
System.Data.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq) +54
System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +110
System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input) +80
System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding) +88
System.Data.Objects.ELinq.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda) +85
System.Data.Objects.ELinq.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) +37
System.Data.Objects.ELinq.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod) +14
System.Data.Objects.ELinq.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) +102
System.Data.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq) +54
System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +110
System.Data.Objects.ELinq.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda) +49
System.Data.Objects.ELinq.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) +37
System.Data.Objects.ELinq.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod) +14
System.Data.Objects.ELinq.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) +102
System.Data.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq) +54
System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +110
System.Data.Objects.ELinq.ExpressionConverter.Convert() +16
System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption) +110
System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +149
System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +44
System.Linq.Enumerable.Any(IEnumerable`1 source) +71
MVC_EDI.Controllers.DirectEDIController.hasTrakNumber(Guid inOrderID) in H:\DirectEDI\MVC_EDI\MVC_EDI\MVC_EDI\Controllers\DirectEDIController.cs:148