0

I have been working in SQL and had recently started LINQ C# queries. I'm trying to write a LINQ query to find all the employees whose job's name starts with A. I want similar results to this SQL query

SQL QUERY

SELECT empno, ename, job, sal 
FROM   emp
WHERE job LIKE 'A%';

LINQ VERSION

from query in conn,EMPs
where query.JOB like 'A%'
select new
{
    query.EMPNO, query.ENAME, query.JOB, query.SAL
}
arekzyla
  • 2,878
  • 11
  • 19
  • Not sure about the oracle provider, but you could try either `where query.Job.StartsWith("A")` or `where SqlMethods.Like(query.Job, "A%")` – sgmoore Jun 26 '18 at 08:35

1 Answers1

0

If you want to stick to the SQL like syntax you can do this way:

from x in context
where x.JOB.StartsWith("A")
select new
{
    x.EMPNO, x.ENAME, x.JOB, x.SAL
};

Or if you don't need projection for the results you can do simply:

from x in context
where x.JOB.StartsWith("A")
select x;

Or you can switch to fluent version like the guy that commented your post did.

EDIT

You could also find useful info here where they talk about this functionality in particular using EF

greyhame
  • 264
  • 2
  • 13