A
A
Alisa Vasilyeva2018-12-13 10:26:03
.NET
Alisa Vasilyeva, 2018-12-13 10:26:03

LINQ to SQL and Enum?

There is the following request:

IQueryable<Header> headers = context.Headers;
IQueryable<Line> lines = context.Lines;
result = headers.Select(header => new ReportModel
                {
                    Comment = header.Comment,
                    Lines = lines.Where(line => line.Header == header.ID).Select(line => new ReportLineModel
                    {
                        SomeProperty = line.SomeProperty,
                        Error = ErrorLine.None
                    })
                }).ToArray();

It shouldn't execute because ErrorLine is an Enum. However, it runs in debug, but crashes in release. What could be the reason? Framework version 4.0
The specified value is not an instance of type 'Edm.Int32'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
basrach, 2018-12-16
@nyarloc

'Edm.Int32'

It is obvious that the standard enum cannot be converted to some kind of 'Edm.Int32'. This is what Wednesday tells you. If at all the problem is in this line.
But since you did not provide class declarations, it may well be that SomeProperty has this strange type, into which linq cannot automatically map the value from the database.

Remembered, edm = Entity Data Model.
Do you have some ancient version of EF? Looks like a bug in earlier versions of EF. Try replacing
with
Error = (ErrorLine)1 // то значение, которое имеет None

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question