-1

I want to convert this SQL to LINQ, but encounter difficulties, can anybody help me? thanks a lot, here is the SQL codes:

select publication_id, publication_code, publication_name 
from tbl_PUBLICATION 
where AIG_PUB = 1 
order by PUBLICATION_NAME

by the way, the AIG_PUB field is bit type,

user2949042
  • 355
  • 2
  • 5
  • 15
  • 3
    And by difficulties you mean what? What did you encounter, what did you research and attempt to overcome that obstacle? – dfundako Jun 08 '18 at 17:04
  • Perhaps my [LINQ to SQL Recipe](https://stackoverflow.com/questions/49245160/sql-to-linq-with-multiple-join-count-and-left-join/49245786#49245786) may prove helpful. Obviously `AIG_PUB` is not boolean in SQL or it wouldn't be comparable to `1` and most SQL servers don't support boolean, so the question is what is it's actual type in SQL? Also, are what database engine/provider are you using? Are you using EF? – NetMage Jun 08 '18 at 17:39
  • i suggest you download linqpad : http://www.linqpad.net/download.aspx and have try its easy – Pranay Rana Jun 08 '18 at 17:54
  • or you can have look to this http://www.sqltolinq.com/ – Pranay Rana Jun 08 '18 at 17:56
  • given my answer have look and try out ...i am not giving you actual answer but you can learn from answer and create query for you – Pranay Rana Jun 08 '18 at 18:00
  • have you have to build query – Pranay Rana Jun 08 '18 at 18:59

3 Answers3

1

Apart from below suggest you make use of LinqPad tool - free, it has sample that can also help you


I am not giving you actual answer but you can learn from answer and create query for you

its simple , you have have look to this image

Sql query

Select firstname,LastName from [User] where id = 3

Converted linq query

enter image description here

You can check this : SQL to LINQ ( Visual Representation )

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
0
tbl_PUBLICATION
.Where(p => p.AIG_PUB)
.OrderBy(p => p.PUBLICATION_NAME);

or if you insist to select only those columns

tbl_PUBLICATION
.Where(p => p.AIG_PUB == true)
.OrderBy(p => p.PUBLICATION_NAME)
.Select(p => new {
    publication_id = p.publication_id,
    publication_code = p.publication_code,
    publication_name = p.publication_name
});
user2949042
  • 355
  • 2
  • 5
  • 15
H.Danesh
  • 53
  • 5
  • thank you so much for your help, H.Danesh, I will try your codes next Monday and let you know then, have a great weekend! – user2949042 Jun 09 '18 at 01:19
0

This should probably do it.

var MyResults = tbl1_PUBLICATION
.Where( x => x.AIG_PUB == 1)
.Select( p => new {
 publication_id = p.publication_id,
 publication_code = p.publication_code,
 publication_name = p.publication_name})
.OrderBy( p => p.PublicationName);

I haven't tested it, so if you see any typos, please let me know,

I Stand With Israel
  • 1,971
  • 16
  • 30
  • thank you so much for your help, I will try your codes next Monday and let you know then, have a great weekend! – user2949042 Jun 09 '18 at 01:19