As I am getting my Linq query to a functional point, I start looking at the query and think about all the "ANY" , and wonder if those should be a different method and then I have data conversions going on.
Does anything jump out as being a performance issue? What is recommended to make this more performant? (Yes I need all the && )
etchVector =
from vio in list
where excelViolations.Any(excelVio => vio.VioID.Formatted.Equals(excelVio.VioID.ToString()))
&& excelViolations.Any(excelVio => vio.RuleType.Formatted.Equals(excelVio.RuleType))
&& excelViolations.Any(excelVio => vio.VioType.Formatted.Equals(excelVio.VioType))
&& excelViolations.Any(excelVio => vio.EtchVects.Any(x => x.XCoordinate.Equals(excelVio.XCoordinate)))
&& excelViolations.Any(excelVio => vio.EtchVects.Any(y => y.YCoordinate.Equals(excelVio.YCoordinate)))
select new EtchVectorShapes
{
VioID = Convert.ToInt32(vio.EtchVects.Select(x => x.VioID)),
ObjectType = vio.EtchVects.Select(x => x.ObjectType).ToString(),
XCoordinate = Convert.ToDouble(vio.EtchVects.Select(x => x.XCoordinate)),
YCoordinate = Convert.ToDouble(vio.EtchVects.Select(x => x.YCoordinate)),
Layer = vio.EtchVects.Select(x => x.Layer).ToString()
};
Ok, so I was "happy" when I saw all the errors messages goes away from when I used
select new EtchVectorShapes()
{
VioID = vio.EtchVects.Select(x => x.VioID),
ObjectType = vio.EtchVects.Select(x => x.ObjectType),
XCoordinate = vio.EtchVects.Select(x => x.XCoordinate),
YCoordinate = vio.EtchVects.Select(x => x.YCoordinate),
Layer = vio.EtchVects.Select(x => x.Layer)
//ObjectType = vio.EtchVectors.Select(x=> x)
}).ToList();
However this gave me all the
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<int>' to'int'
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<string>' to'string'
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to'double'
So I eagerly changed to:
VioID = Convert.ToInt32(vio.EtchVects.Select(x => x.VioID)),
ObjectType = vio.EtchVects.Select(x => x.ObjectType).ToString(),
XCoordinate = Convert.ToDouble(vio.EtchVects.Select(x => x.XCoordinate)),
YCoordinate = Convert.ToDouble(vio.EtchVects.Select(x => x.YCoordinate)),
Layer = vio.EtchVects.Select(x => x.Layer).ToString()
but this sadly ends in error with :
Unable to cast object of type 'WhereSelectListIterator`2[DTD.ManagedMPS.Core.EtchVectorShapes,System.Int32]' to type 'System.IConvertible'.
ToList()
call? This will (of course) freeze the enumerable contents at creation time, so maybe this is hat you require; but maybe not. – Pieter Geerkens May 11 '13 at 1:21