0

I am trying to convert link query in vb below to C#. I have never previously done vb and linq query before, I have converted to SQL but what would this be in linq c#,

VB script

 Dim d = (From p In db.tblkeyPages Join keypagetype In db.tblkeyPageTypes On p.keyPageType Equals keypagetype.keyPageType Where keypagetype.keyPageType = 1 Select p.pageContent).First

SQL

select d.keyPageType, d.pageContent from dbo.tblkeyPage as d
join (select keyPageType from dbo.tblkeyPageType )as s 
on d.keyPageType = s.keyPageType
where s.keyPageType = 1
2
  • Do you have any progress on converting to C#? Commented Dec 10, 2013 at 16:55
  • @X.L.Ant: You should try this first. Commented Dec 10, 2013 at 18:52

1 Answer 1

2

Here is good starting point: Introduction to LINQ Queries (C#)

var content = (from p in db.tblkeyPages 
               join keypagetype in db.tblkeyPageTypes 
                    on p.keyPageType equals keypagetype.keyPageType
               where keypagetype.keyPageType == 1
               select p.pageContent).First();

Also I suggest you to spend time learning C# syntax. As you can see, query looks almost same (just keywords are lower case, because C# is a case-sensitive language)

One more note - if you want to avoid exception, then use FirstOrDefault() instead of First() when it is possible that no results will be returned by query.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help.. that link really helped in link query.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.