sgmoore

About

Username
sgmoore
Joined
Visits
1,274
Last Active
Roles
Member
Points
74
Badges
9
  • Re: Is there a more optimal/elegant way to implement sub queries?

    You can use the let command to avoid duplication, eg
    var providers = ( from p in matches group p by new { p.Provnum, p.actualPhone } into g let CustomerList = ( from cl in matches where cl.actualPhone == g.Key.actualPhone orderby cl.CUSTNMBR.Length select cl.CUSTNMBR ).ToList() select new { Provnum = g.Key.Provnum ,Phone = g.Key.actualPhone ,CustomerCount = g.Count() , CustomerList ,PrimaryCustomerNumber = CustomerList.First() }

    I have also replaced your select new { cl.CUSTNMBR } with select cl.CUSTNMBR which isn't necessary, but is probably more efficient.
    You are already filtering and ordering matches so there is no need for the section where providerIds.Contains( p.Provnum ) orderby p.Provnum

    I don't what your data layout is, but it looks like you are grouping by Provnum and actualPhone, and then for each group you are selecting all matching phonenumbers ignoring the value Provnum. If this is deliberate, then that's ok, but if you are looking for the all records which match both phonenumbers and Provnum, then you can further simplify your code to CustomerList = g.Select(a=>a.CUSTNMBR).ToList(),

    Most of these would make your code smaller and maybe more readable, but I don't think it would have much effect with execution speed. With Linq2Sql you need to be careful to make sure the TSQL generated is efficient. (Of course, one of the benefits of LinqPad is that you can see easily see what TSQL is being generated).

    In this example, since matches is doing the filtering, you might find it more efficient to perform the grouping in memory, rather than asking SQL to do it. This can be done simply by adding .ToList() to the end of your matches declaration.
  • Re: Reference for learning basic LINQ for SQL? C# Expressions or C# Statements

    The compile error you are getting is because you have to name each member in the anonymous type and hence can't just use a constant.

    Also, in order to compare the anonymous types, they must contain the same names and types. so you would need something like (assuming Inactive is an int)

    new { p.PHONE ,r.INACTIVE } equals new { PHONE = r.PHONE1 ,INACTIVE = 1 }

    If it is a bool, then you would need
    new { p.PHONE ,r.INACTIVE } equals new { PHONE = r.PHONE1 ,INACTIVE = true }

    or if it is nullable you would need
    new { p.PHONE ,r.INACTIVE } equals new { PHONE = r.PHONE1 ,INACTIVE = (bool?) true }
  • Re: Query results limited to 40 rows

    There seem to be some Linq Providers that limit the number of results if you don't specify how many you want. The solution is to use something like .Take(1000) or .Take(1000000) if you really can cope with a million records.
  • Re: Version 5 AnyCPU getting 2GB error

    X64 won't solve this issue.

    File.ReadAllBytes has a specific check to make sure the length is less than 2Gb

    See https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/IO/File.cs

    And the reason for that check is because you can't have a single array bigger than 2GB.

    See

    https://stackoverflow.com/questions/2415434/the-limitation-on-the-size-of-net-array

  • Re: How do I get monospaced results

    Edit/Preferences/Results.

    Set the Style Sheet for text (HTML) results to custom and click on Launch Editor and then you can add
    body
    {
    	margin: 0.3em 0.3em 0.4em 0.4em;
    	font-family: Consolas;
    	font-size: 80%;
    	background: white;
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Badges