Creating a Linq statement to create objects

If I created the Linq statement as shown below, it works fine.

var Jobs = from a in ctx.MyExport
           select new
           {
               FileName = a.FilePath,
               JobId = a.ID,
           };

If I want to use a class rather than an anonymous type, I get the following error: "It is not possible to convert a lambda expression to type" string "because it is not a delegate type."

Here is the code I want to work:

var Jobs = from a in ctx.MyExport
           select new MyClass
           {
               FileName = a.FilePath,
               JobId = a.ID,
           };

And here is the class:

public class MyClass
{
    public string FileName { get; set; }
    public Guid JobId { get; set; }
}

Can someone tell me what I'm doing wrong and how to fix it?

+3
source share
1 answer

The above code is correct, you receive an error message due to a code that you did not show us.

, . IEnumerable , , , . .

, , , foreach , Jobs.AsEnumerable() Jobs.ToList() ( , ) - , .

+1

Source: https://habr.com/ru/post/1730357/


All Articles