Why does a class transition connect when I use LINQ?

I have a method that takes three parameters: List<Class1> source , List<Class2) results and DateTime endDate . I see why the cool connection is four. However, when I add this expression, it jumps to ten minutes:

 var warnings = from s in source join r in results on s.Field1 equals r.Field1 into joined from j in joined.DefaultIfEmpty( ) where j == null select string.Format( "{0}{1}", A_CONSTANT, s.Field2 ); 

My questions:

  • What six new classes were introduced by the LINQ operator?
  • And since ten is the upper limit of โ€œgood code,โ€ does that mean LINQ is not the best choice here?
+6
source share
1 answer

Perhaps six additional classes:

  • IEnumerable<string> - the result of your request
  • IEnumerable<Class1> - left collection
  • IEnumerable<Class2> - right collection
  • Func<Class1, int> - the left side of the union expression
  • Func<Class2, int> - the right side of the union expression
  • Func<Class1, Class2, string> - projection

It is also possible that it counts the Enumerable class, as the request translates into calls to the static extension method.

In any case, code analysis does not seem to ignore the transition classes used by Linq (should it be debatable or not). My advice is either to ignore it (perhaps by manually counting the relationship and noting the difference), or to find the best analysis tool.

Another question: can it increase your connection as a whole? I suspect that some of these classes are used throughout the application, so it cannot significantly affect the overall connection.

+5
source

Source: https://habr.com/ru/post/985270/


All Articles