An expression tree may not contain an access of static abstract interface member #5997
Replies: 1 comment 7 replies
-
A lot of newer language features are not supported by expression trees. See #4727 and #158 for discussions on modernizing them. Back in August 2021 the LDT expressed interest in looking at this sooner rather than later:
My understanding is that the EF team is currently working on a more formalized spec for how this modernization will happen. Not sure if static abstracts is something they plan to add or if they're focusing on features that have already shipped. (@AndriySvyryd probably knows.) |
Beta Was this translation helpful? Give feedback.
-
I'm using value objects for all properties of entities. Since a lot of them are of type string that just have a min and max length, I created a base class that has the common code. To use value objects with EF Core I need a seperate converter for each type. Therefore I was trying to use the new preview feature of static abstract methods in interfaces.
Static interface members should finally make it possible to call a static factory to create the object, but
T.Create(v).Value
produces a compile error stating:What is this limitation about? Is it a limitation of the preview feature? Is there another way to achive the goal differently?
The converter looks like this:
I then can use in fluent api:
.HasConversion(DBConverter<ProductComment).TextConverter)
The interface is defined as:
The base class for text value objects is defined as:
(The FieldKey is a lambda to a resource key, which allows multi-language error messages. They key is checked at compile time.)
For creating a new value object type, for example ProductComment, I just need to write this code:
Beta Was this translation helpful? Give feedback.
All reactions