c# - whats wrong in this LINQ synatx? -


I am trying to convert SQL query to LINQ. Somehow my counting (different (x)) logic is not working properly. The original SQL is quite efficient (either I think), but the generated SQL is also not returning the correct result.

I am trying to do this to correct LINQ, what is doing the original SQL, and doing it in an efficient manner as the original question. Here I can be helped because I'm stuck here: (

The SQL that is working and I want to be equal to LINQ's:

  SELECT [ T1]. [[Code] AS [T] Inner Join [DBO]. [FOSSON] AS [T1] ON [T1]. [PHONEcode] = [T.]. [Code] Inner Join [ [Person] at [t1]. [Personality] = [dbo]. [Person] .PersonIDID WHERE ([T.]. [Code type] = 'phone') and (([tt]]. [Codedescription] = 'Home') and ([T1]. [Phononum] = '111') or ([T.]. [CodeDiscover [T1] [personality] [(1 t1)] [phone1]] = 2   

The LINQ I created is almost down to:

  var ids = context.Code.Where (predicate); var rs = new group {r.phonenumbers.person. PersonID} from R group with R = R with matchcount = G. select (P => p.phoneenumbers .fonnum) .edit () .count () where matchcount == 2 choose ne w {personid = g .Key};  

Unfortunately, the above LINQ is not producing the correct result, and in fact internally Sector is generated on SQL shown. By the way, this generated query is also reading all the rows (approximately 1959, 2040) due to the COUNTS: (This is also a big demonstration issue. Please help / point me in the right direction.

Announcement
  Declaration @ W. Warkar (10) = 'Phone' declare @ P1 Warkar (10) = declare 'Home' @ P2 VarChar (10) = '111' Announce @P3 VarChar (10) = 'Work' P4 VarChar (10) = '222' Declare @ P5 VarChar (10) = Select '2' [T9]. [Personality], (SELECT COUNT (*) FROM ( SELECT DISTINCT [T13]. [PhoneNum] FROM [dbo] [Code] AS [T10] Inner Joy [DBO]. [FONES] AS [T11] ON [T11]. [PHONE TYPE] = [T10]. [Code] Inner Join [DBO]. [Person] at AS [T12] [t12]. [PersonID] = [t11]. [PersonID] Inner Join [DBO]. [Phonebus] AS [T13] On [T13]. [Phone Type] = [T10]. [Code] WHERE ([T 9] [PersonID] = [t12]. [Person]] and ([T10]. [Codic] = @ P) and ((([T10]. [Code type] = @ P1) and ([T 11]. [Phononum] = @ P2) or (([T10]. [Codetype] = @ P3) and ([T11]. [Phononum] = @ P4))) [T14] ) From [CTT] as [selection] [personality], (select number (*) from (selection) T [t7]. [Phone number] from [dbo] [Code] AS [T4] Inner Join [DBO]. [FOONN] AS [T5] ON [T5]. [Phone type] = [t4]. [Code] Inner Join [DBO]. [Person] AS [T6] On [T6] [Personaad] = [T5]. [Personality] INNER JOIN [dbo] [Phone] [t7] at [t7]. [Phone type] = [t4]. [Code] WHERE ([T3]. [Personality] = [T6]. [Personality]) and ([T4]. [Codetype] = @ p0) AND ((([[t4]] [Codetype] = @ P1) and ([T5]. [Phononum] = @ P2) or (([T4]. [Codetype] = @ P3) and ([T5]. [Phononum] = @ P4)) AS [T8]) from AS [Value] (Select [T2]. [Persona] [DBO]. [Code] AS [T] INNER JOIN [DBO]. [Phone 1] at [T1] . [Phone Type] = [T.]. [Code] Inner Join [DBO]. [Person] AS [T2] On [T2] [personID] = [T1]. [Personality] WHERE ([T ] [Codetype] = @ p0) and ((([T.]. [Codic] = @ P1) and ([T1]. [Phononum] = @ P2) or ([[T.]. [Codic type] = @ P3) and ([T1]. [Phonenum] = @ P4) Group by [T2]. [Personia]] AS [T3]) AS [T 9] WHERE [t9]. [Value] = @ p5  

Thanks!

I think this issue may be that the new {r.phonenumbers.person. PersonID} .

Why are you renewing the new object, code> r.phonenumbers.person directly? The new {} is going to be a different object every time, which will never be a group.

After grouping by person, I select Select a group = & gt; New {person = group. Page, phone number = group.posor.phonnumber} and then check how many phone numbers they are and then a final projection.


Comments