in Education by
Is there any way to convert following SQL statement into LINQ? select ve.EntityID , fin1.FinanceStat as FinanceStat_New , fin2.FinanceStat as FinanceStat_Old from ValuationEvents_PIT_New as ve left join FinStat_New as Fin1 on ve.EntityID = Fin1.EntityID left join FinStat_Old as Fin2 on ve.EntityID = Fin2.EntityID where Fin1.FinanceStat ne Fin2.FinanceStat and Fin2.FinanceStat is not null and charindex(Fin1.FinanceStat, 'abc') < 1 and charindex(Fin1.FinanceStat, 'xyz') < 1 Here is my version of it, but I need extra pair of eyes to look at it. var result = (from ve in valuationEventsPit join fsn in finStatNew on ve.EntityId equals fsn.EntityID into veFsn from fin1 in veFsn.DefaultIfEmpty() join fso in finStatOld on ve.EntityId equals fso.EntityID into veFso from fin2 in veFso.DefaultIfEmpty() select new { ve.EntityId, FinStatNew1 = fin1 == null ? null : fin1.FinanceStat, FinStatNew2 = fin2 == null ? null : fin2.FinanceStat }). Where(x => x.FinStatNew1 != null && x.FinStatNew2 != null && x.FinStatNew1 != x.FinStatNew2 && !(x.FinStatNew1.Contains("abc")) && !(x.FinStatNew1.Contains("xyz"))).ToList(); The reason I am excluding x.FinStatNew1 == null because of the charindex(Fin1.FinanceStat, 'abc') < 1, which will always return 0 if x.FinStatNew1 is not null and 'abc' or 'xyz' is not there and if x.FinStatNew1 is null then it will return null and condition still will be false (null < 0). Thanks a lot for your help. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I think you could reduce that query even more and rearrange some things to make it more readable. Based on the original query and these are actually LINQ to objects queries, I'd try this: const string con1 = "abc"; const string con2 = "xyz"; var query = from ve in valuationEventPit join fsn in finStatNew on ve.EntityId equals fsn.EntityID join fso in finStatOld on ve.EntityId equals fso.EntityID let FinStatNew = fsn.FinanceStat let FinStatOld = fso.FinanceStat where FinStatNew != FinStatOld && FinStatOld != null && new[]{con1,con2}.All(con => !FinStatNew.Contains(con)) select new { ve.EntityId, FinStatNew, FinStatOld }; The left join is not necessary here. Since you exclude the null values, we could just ignore them then and do the inner join.

Related questions

0 votes
    I'm new in LINQ so I hope this isn't a stupid question: I have a table with a lot of ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I'm new in LINQ so I hope this isn't a stupid question: I have a table with a lot of ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I'm new in LINQ so I hope this isn't a stupid question: I have a table with a lot of ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I'm new in LINQ so I hope this isn't a stupid question: I have a table with a lot of ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    How to achieve Left Excluding JOIN using LINQ? In SQL: SELECT FROM Table_A A LEFT JOIN Table_B B ON ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    Which oracle is the join condition is specified using the WHERE clause: (a) Oracle 9i (b) Oracle ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    I have a table containing the last comments posted on the website, and I'd like to join a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    I have a table containing the last comments posted on the website, and I'd like to join a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I have a table containing the last comments posted on the website, and I'd like to join a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    I have a table containing the last comments posted on the website, and I'd like to join a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    I have two tables containing Tasks and Notes, and want to retrieve a list of tasks with the number ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    I am getting empty row on following sql SELECT * FROM flyers WHERE fId='6' AND 'userId'='400' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    ANSI-standard SQL allows the use of special operators in conjunction with the WHERE clause. A special ... Schemes topic in chapter Concurrency Control of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    Greetings! I'm working on wrapping my head around LINQ. If I had some XML such as this loaded ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    He passed the exam. He told me this. (join with adjective clause ). Select the correct answer from above options...
asked Dec 20, 2021 in Education by JackTerrance
...