-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search by value object's Value property: Translation error #399
Comments
If i got it right your public sealed class Book
{
// ...
public Title Title { get; set; }
} and your Title object is like public struct Title
{
private string _value;
public string Value => _value;
public short MaxLength => 200;
public static Title Create(string title)
{
// checks on input ...
_value = title;
}
} in this case your conversion for the builder
.Property(x => x.Title)
.HasConversion(x => x.Value, x => Title.Create(x)) // <-- Remove the final .Value from Title.Create()
.HasMaxLength(Title.MaxLength)
.IsRequired() // This can be omitted if title is not null in Book |
@enrij That's almost exactly what I have, but my Title.Create() function returns either errors or the Title object. So the Title.Create(x).Value is needed in the EF Core configuration. I am using the ErrorOr library so the actual method looks like:
Do you think because I have it configured that way, it's the cause of the issue with translation? I'll change the code a bit and see if that is indeed the issue. I did find a work around to my issue, but it's not pretty.
|
I found my issue. I misconfigured the EF configuration. My original configuration worked in almost every case until I tried to use it in the Search. I then realized that some of my objects worked fine in search, such as Author.Email. The Author object is setup as a complex property, while my Title is not. I changed:
to
And now I can use the following:
Thanks @enrij, you set my mind in the right direction. |
I have a defined value object called Title, which exposes its value through a property called "Value" (i.e. Title.Value). I am using EF Core 8.0 and have the value object defined as:
When I try to use the Query.Search() function, I am receiving an error that it could not be translated.
Examples:
Error:
I know this isn't directly related to the specification package, but I'm looking for some help and maybe a new feature.
Maybe something along the lines of:
Is there another approach I could take to use this value object in the search?
The text was updated successfully, but these errors were encountered: