this will help Write the clearest code you can, and then benchmark and profile to discover any performance problems. If you do have performance problems, you can experiment with different code to work out whether it's faster or not (measuring all the time with as realistic data as possible) and then make a judgement call as to whether the improvement in performance is worth the readability hit. A direct foreach approach will be faster than LINQ in many cases. For example, consider:
var query = from element in list
where element.X > 2
where element.Y < 2
select element.X + element.Y;
foreach (var value in query)
foreach (var element in list)
if (element.X > 2 && element.Y < 2)
Console.WriteLine(element.X + element.Y);
var query = from item in firstSequence
from nestedItem in item.NestedItems
select item.BaseCount + nestedItem.NestedCount;
LINQ to SQL: filter nested objects with soft deletes
I wish this helpful for you So far I found only one suitable solution for this (apart from not to use soft deletes at all): to delete the soft-deletion relationship on entity update. E.g. when I decided to remove a file from the document, I perform something like:
// this may be a part of update method
var file = document.File;
// attach soft deleted file
// remove a file reference
document.File = null;
// attach document entity and submit changes
Rewrite nested foreach with linq if there are some operations apart from internal foreach loops
fixed the issue. Will look into that further Whole code is quite suspicious as variable cT is only added to List, neither of it`s properties is checked inside foreach loop. Either this is original behaviour or consequence of obfuscation, you should revise your sample.
List<complexType> listOfComplex = ...some list...
//List<complexType> newListOfCOmplex = new List<complexType>();
SomeObjectType someObject = ...some object...
//Totaly unneccessary as newListOfCOmplex is complete copy of listOfComplex
//foreach(var cT in listOfComplex)
var someObjectPropertyValue = someObject.property.FirstOrDefault(a=>a.value == smth) ?? return null;
var t = someObjectPropertyValue.Something.AnotherSomethin ?? return smth;
var collection = t.Where(s=>(s.value == firstValue || s.value == secondValue) ).ToList();
foreach (var f in collection) someOtherMethod(f);
Query/Filter by nested objects getting unexpected results in some nested objects
I hope this helps . From the mapping it looks like the index has a type of category as well as a field in attribute type called category. To allow for proper field resolution and disambiguate between field id in type category vs field category.id in type attribute you would need to specify the entire path to the field including the type i.e ..