c# - The following code has the same result, but whichever is faster in bringing the result -
the first code used "join"
but in second code not used "join"
note result same.
so have several questions
which better?
which faster?
code01:
(from member in dcontext.tb_familycardmembers select new { member.familycard_id, member.tb_familycard.nofamilycard, cardtype = member.tb_familycard.is_card == true ? "دفتر عائلة" : "بيان عائلي", firsn = member.tb_person.firstname, fathern = member.tb_person.fathername == null ? selectpersonbyid(int.parse(member.tb_person.father_id.tostring())).firstname : member.tb_person.fathername, lastn = member.tb_person.lastname == null ? selectpersonbyid(int.parse(member.tb_person.father_id.tostring())).lastname : member.tb_person.lastname, mothern = member.tb_person.mothername == null ? selectpersonbyid(int.parse(member.tb_person.mother_id.tostring())).firstname : member.tb_person.mothername, motherln = member.tb_person.motherlastname == null ? selectpersonbyid(int.parse(member.tb_person.mother_id.tostring())).lastname : member.tb_person.motherlastname }).tolist(); ______________________________________________
code02:
(from member in dcontext.tb_familycardmembers join card in dcontext.tb_familycards on member.familycard_id equals card.id join person in dcontext.tb_persons on member.person_id equals person.id select new { member.familycard_id, card.nofamilycard, cardtype = card.is_card == true ? "دفتر عائلة" : "بيان عائلي", firsn = person.firstname, fathern = person.fathername == null ? selectpersonbyid(int.parse(person.father_id.tostring())).firstname : person.fathername, lastn = person.lastname == null ? selectpersonbyid(int.parse(person.father_id.tostring())).lastname : person.lastname, mothern = person.mothername == null ? selectpersonbyid(int.parse(person.mother_id.tostring())).firstname : person.mothername, motherln = person.motherlastname == null ? selectpersonbyid(int.parse(person.mother_id.tostring())).lastname : person.motherlastname }).tolist();
all roads lead rome
just because there no join in linq code, not mean there no join in final query.
once use
member.tb_person.firstname
linq-2-sql post add join generated sql.
a lot of coders explicitly add join because coding linq-2-sql in real sql kind of way. of times not needed (assuming proper foreign keys in place) because l2s figure join out you.
to answer question need profile actual sql generated. see difference in query sent database. chances identical. if not, select efficient of two.
how view sql: how view linq generated sql statements?
Comments
Post a Comment