I have the following linq code
var advertisements = _applicationContext.Advertisings.ToList();
var stepsData = advertisements.Select(a => new[]
{
new
{
number = a.Number,
text = a.Text,
image = a.Image,
type = a.Type,
data = (a) =>
{
if (string.IsNullOrEmpty(a.Link) || string.IsNullOrEmpty(a.Deeplink))
{
return null;
}
return new
{
link = a.Link,
deeplink = a.Deeplink
};
}
}
});
See on the data
property. A value of this property depends on values Link
and DeepLink
of item a
. The a
is an instance of the following model:
public class Advertising
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public int Number { get; set; }
public string Text { get; set; }
public string Image { get; set; }
public string Type { get; set; }
public bool Show { get; set; }
public string Link { get; set; }
public string Deeplink { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public Advertising()
{
CreatedAt = DateTime.UtcNow;
UpdatedAt = DateTime.UtcNow;
}
}
All is good, but I see a notification from IDE
A local or parameter named 'a' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
How to use lambda in this case? I need to pass into the lambda variable a
. Without params, it shows me the following error
Cannot assign 'lambda expression' to anonymous type property
Update
Lambda without params gives me the following result
Error text:
Cannot assign 'lambda expression' to anonymous type property