How do I convert this sql to a linq query?

Try: from att in context. Attendees join webUsers in context. WebUsers on att.

Web_user_id equals webUsers. Id join invoice in context. Invoice on att.

InvoiceID equals invoice. ID where invoice. SeminarID == seminarId select new { webUsers.

FirstName, att. InvoiceID }.

Awesome! That worked. Thank you – majid Nov 4 at 21:08 No worries.

Glad I can be of help. :) – ysrb Nov 4 at 21:11 @majid, show your appreciation with up votes on stackoverflow – IAbstractDownvoteFactory Nov 4 at 21:51.

Start by cleaning up the SQL. Don't mix joins and implicit joins in the query, use explicit joins for both: select invoice. Id, web_users.

Id, web_users. First_name, web_users. Last_name,web_users.

Email_address from attendees inner join web_users on web_users. Id = attendees. Web_user_id inner join invoice on invoice.Id = attendees.

Invoice_id where invoice. Seminar_id = 6 Now I think that it translates: from att in context. Attendees join webUsers in context.

WebUsers on webUsers. ID equals att. WebUserID join invoice in context.

Invoice on att. InvoiceID equals invoice.ID where invoice. SeminarID == seminarId select new { webUsers.

FirstName, att. InvoiceID }.

Thanks for the advice. That is sound advice. The other answer by ysrb was first so it was my accepted answer – majid yesterday.

Start by cleaning up the SQL. Don't mix joins and implicit joins in the query, use explicit joins for both.

Var query = from acc in db. Join accOwner in db. AccOwners on {acc.

You can use LinqPad or Linqer I would try to convert it in LinqPad, but I would have to have the database.

You can use LinqPad or Linqer. I would try to convert it in LinqPad, but I would have to have the database.

Dample: I have LinqPad but I don't see option to convert SQL to Linq – DotnetSparrow Apr 1 at 13:10 @DotnetSparrow check this link (i51.tinypic. Com/2heajup. Png) – Dampe Apr 1 at 13:15 You should get 'translations' of your query (it works like this for linq queries) in sql and lambda.. same behaviour should work in other direction (sql>linq).

Even if it won't work as you need, you can still use Linqer, which is actually a SQL to LINQ tool. So I don't understand why I am getting downvotes on this. – Dampe Apr 1 at 13:18 @dample: I used this and When I click the lambda there is no LINQ although Results tab show 1700 count – DotnetSparrow Apr 1 at 13:19 @DotnetSparrow: Then try Linqer.

– Dampe Apr 1 at 13:22.

Converting this to Linq should be pretty easy - although I think you should use a join if you want the same query! First create your Linq2Sql model and import your 2 tables, then your query will have the general structure var query = from acc in db. Accs join accOwner in db.

AccOwners on {acc. RegId, acc. AccountNo} equals {accOwner.

RegId, accOwner. AccountNo} where // your where conditions // - these should all convert quite easily // - just translate them one by one select acc; var count = query.Count(); If you really need to use subquery then since you are an expert in SQL, then write the query out in SQL first, then test it, then translate the query across to Linq, then test it - taking the translation line by line you'll be fine - and you'll also find Intellisense is wonderful! Please also realise that if you use .Include() then you are probably using join within the generated SQL anyway.

Thanks but I need to use subquery or include and no joins – DotnetSparrow Apr 1 at 13:26 In that case I've updated my advice - first use the fact that you are an expert in SQL to translate the query to non-Join format in SQL first. – Stuart Apr 1 at 13:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions