Skip to content

Casting a int to a nullable int will throw an error when using linq to entities"Only parameterless constructors and initializers are supported in LINQ to Entities" #44

@Adam1-1593

Description

@Adam1-1593

Using an expression in the following format - MyDbSet.Select("new (int?(Id))") will throw an error if the Id property is of type int. This seems to be a bug in the original System.Linq.Dynamic project too.

One work around I have found is you can cast it to int64 first and then a nullable int like so MyDbSet.Select("new (int?(int64(Id)))")

The error only gets thrown once you try to evaluate the expression e.g. calling Count() on the first example

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions