how to convert raw sql to entity linq

Shahzaib khan 6 Reputation points
2020-09-16T02:00:42.337+00:00

select distinct Users.Name,Packages.PName,Packages.Price,RefEarning=(select Price*ReferCommission/100)
from Users inner join UserPackages on UserPackages.U_ID=Users.ID
inner join Packages on Packages.PID=UserPackages.P_ID
inner join Refers on Users.Ref_No=Refers.RefOf
where exists(
select Users.ID from users where Refers.RefOf='Gerfwscv6kOwnIM8hl_TiA'
) and UserPackages.PackageStatus='true'

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
8,505 questions
1 vote

2 answers

Sort by: Most helpful
  1. Miamiao-MSFT 4,216 Reputation points
    2020-09-16T06:10:00.507+00:00

    Hi @Shahzaib khan

    I recommend you could try online converter:

    Linqer : sqltolinq

    You can reference : linqer-a-nice-tool-for-sql-to-linq-transition ,

    An SQL-> LINQ converter.

    Or LINQPad: linqpad

    BR,
    Mia


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    No comments

  2. Shahzaib khan 6 Reputation points
    2020-09-16T03:41:25.613+00:00

    got it working with this

    var data = (from u in db.Users join up in db.UserPackages on u.ID equals up.U_ID
                            join p in db.Packages on up.P_ID equals p.PID
                            join r in db.Refers on u.Ref_No equals r.RefOf where /*(from u2 in db.Users select u2.ID).Any() && */ r.RefOf.Equals("GDnA47D6XkOwnIM8hl_TiA") && up.PackageStatus == true
                            select new ReferralsListView
                            {
                                Name = u.Name,
                                Package = p.PName,
                               Price = p.Price,
                                YouEarned = (p.Price * p.ReferCommission / 100),
    
    
                            }).Distinct().ToList();