Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ SQL
Hi
I am trying in this linq query which is in VB.Net.
 
I want to use it in c#
 
Can you Help Me
 
From e In db.Stat_Elements _
                      Join a In db.tActors _
                    On a.guId Equals e.ActorGuid _
                 Where e.Value > 0 And e.Segment >= segmentFrom And e.Segment <= segmentTo And e.PeriodId >= fromPeriod And
           e.PeriodId <= toPeriod And ((a.lEANSuppLoc And accessBitmask).Equals(accessBitmask)) _
                    Group By e.DefinitionId _
                   Into Antall = Count(), Verdi = Sum(e.Value * scaleFactor), AntallSolgt = Sum(e.UnitsSold) _
                      Where Antall >= 1 And DefinitionId = definitionIdParam _
                  Select Antall, Verdi, AntallSolgt;
Posted 1-Jun-12 0:07am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This Code Help Me.
 
using System;  
using System.Collections.Generic;  
using System.Linq;  
 
namespace Aggregate  
{  
    class MyData  
    {  
        public DateTime StartDate;  
        public DateTime EndDate;  
        public string type;  
    }  
 
    class Program  
    {  
        static void Main(string[] args)  
        {  
            List<mydata> myDataList = new List<mydata>();  
 
            myDataList.Add(new MyData() { StartDate = new DateTime(2008, 06, 19), EndDate = new DateTime(2008, 06, 25), type = "1" });  
            myDataList.Add(new MyData() { StartDate = new DateTime(2008, 06, 20), EndDate = new DateTime(2008, 06, 25), type = "1" });  
            myDataList.Add(new MyData() { StartDate = new DateTime(2008, 06, 20), EndDate = new DateTime(2008, 06, 28), type = "1" });  
            myDataList.Add(new MyData() { StartDate = new DateTime(2008, 06, 22), EndDate = new DateTime(2008, 06, 25), type = "2" });  
            myDataList.Add(new MyData() { StartDate = new DateTime(2008, 06, 22), EndDate = new DateTime(2008, 06, 26), type = "2" });  
            myDataList.Add(new MyData() { StartDate = new DateTime(2008, 06, 23), EndDate = new DateTime(2008, 06, 24), type = "3" });  
            myDataList.Add(new MyData() { StartDate = new DateTime(2008, 06, 19), EndDate = new DateTime(2008, 06, 27), type = "4" });  
 
            var result =  
                from recod in myDataList  
                group recod by recod.type into g  
                select new {type = g.Key, StartDate = g.Min(record => record.StartDate), EndDate = g.Max(record => record.EndDate) };  
 
            foreach (var row in result)  
            {  
                Console.WriteLine("{0}\t{1}\t{2}",  
                   row.type,  
                   row.StartDate.ToString(),  
                   row.EndDate.ToString());  
            }  
 
            Console.ReadKey();  
        }  
    }  
}
  Permalink  
v2
Comments
Prasad_Kulkarni at 1-Jun-12 5:48am
   
Good work, +5! for sharing code..
sunandandutt at 1-Jun-12 5:50am
   
Thanks Prasad_Kulkarni!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Did you try at all?
 
Have a look at these tools:
Code Translation for .NET (C#<->VB.NET)[^]
Developer Fusion Convert C# to VB.NET [^]
 
There are more on the web. But they would not convert 100% successfully. These would help you to get a base to start with. Manual is the final and best way. Converters would help you greatly in converting. Use it, try and post specific if you get stuck.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

For a linq query, the syntax is the same, all you should have to do is remove the line continuation characters at the end of the lines, change the key words to lower case (From => from, Into => into) and combine some keywords together (Order By => orderby, Group By => groupby ). Of course need to end the query with the c# ";". In fact, you can probably just remove the line continuation characters in VB since they are only required when there could be two meanings without the line continuation.
 
For a simple linq query in VB:
 
Dim customersByCountry = From cust In customers
                         Order By cust.Country, cust.City
                         Group By CountryName = cust.Country
                         Into RegionalCustomers = Group, Count()
                         Order By CountryName
 
The only change would be to change the Dim to var:
 
var customersByCountry = from cust in customers
                         orderby cust.Country, cust.City
                         groupby CountryName = cust.Country
                         into RegionalCustomers = Group, Count()
                         orderby CountryName;
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 1 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100