When using linq in an EF query, i get a strange result in compiling. Below you find a piece of code where i reuse the variable t in the lambda function. On my local PC, visual studio does not generate an error and compiles and runs correctly. But when the piece of code is compiled by an azure devops pipeline, error CS0136 is generated:
A local or parameter named 't' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
I use VS2019 on my local machine and VS2019 on the agent server for devops (Note: this is a self-hosted agent!)
using(Context db = new Context())
{
var orderInformation = db
.Orders
.Where(t => t.Enabled)
.Select(t => => new
{
t.ID,
t.Name,
ExtraInfo= t
.Information
.Where(t => t.OrderDate >= startDate && t.OrderDate <= endDate)
})
.ToList()
}
The correct syntax should be:
using(Context db = new Context())
{
var orderInformation = db
.Orders
.Where(t => t.Enabled)
.Select(t => => new
{
t.ID,
t.Name,
ExtraInfo= t
.Information
.Where(x => x.OrderDate >= startDate && x.OrderDate <= endDate)
})
.ToList()
}
The difference is the lambda parameter in the inner where. My local visual studio accepts both examples, but the visual studio on our azure agents throws a compile error on the first