Does Ling produce redundancy?

I refer to examples in How to combine data with Linq using joins . We have two lists in which human objects are stored (first and last name). The second list contains Pet (Name) objects that contain the face object (pet owner). One person can own> = 0 pets.

What happened now, I made a group connection

Dim result1 = From pers in people Group Join pet in pets on pers Equals pet.Owner Into PetList = Group 

LinqPad shows me the result:

LinqPad Output

It seems to me that Linq makes a lot of layoffs (but I could be wrong here!). The first result object will hold the human object three times. Here for me there are two questions like Linq nooby (but maybe I am reading the result wrong):

  • Are object object references? Unfortunately, I could not find anything.
  • Following the above example, the query continues with
 Select pers.FirstName , pers.LastName, PetName = If(pet is Nothing, String.Empty, pet.Name) 

If we have all the information about the Person object in PetList, why not just request this object? In my opinion, we no longer need pers Object.

+5
source share
1 answer

Yes, these Person objects are references. LINQ does not clone Person objects.

The reason for this conclusion is that LINQPad is trying to show you who this person is. Without repeating walks through its properties and fields, it would be difficult to say which person it belongs to.

+4
source

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


All Articles