如何在“LINQ”中创建这个SQL代码?

时间:2017-06-04 13:49:35

标签: sql linq-to-sql

select top 10 JobId,Title,

(SELECT TOP 1 Authorized FROM Company WHERE CompanyId=Job.CompanyId) as CompanyName

from Job

如何在“LINQ”中创建这个sql代码?

1 个答案:

答案 0 :(得分:0)

您可以尝试类似

的内容
foreach (Variety variety in varieties.ToList())
{
    if (variety.Type != main.Type && variety.Type != null)
    {
         varieties.Remove(variety);
    }
}

假设您将至少拥有一家公司,否则您可能必须使用var query = (from j in job select new { j.JobId, j.Title, CompanyName = (from c in from Company where c.CompanyId=j.CompanyId) select c.Authorized ).First() } ).Take(10);