Giter Club home page Giter Club logo

Comments (3)

jtrose22 avatar jtrose22 commented on June 26, 2024 1

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:

builder
    .Property(x => x.Title)
    .HasConversion(x => x.Value, x => Title.Create(x).Value)
    .HasMaxLength(Title.MaxLength)
    .IsRequired();

to

builder
    .ComplexProperty(x => x.Title, b =>
    {
        b.Property(x => x.Value)
        .HasColumnName("Title")
        .HasMaxLength(Title.MaxLength)
        .IsRequired();
    });

And now I can use the following:

Query.Search(x => x.Title.Value, filter);

Thanks @enrij, you set my mind in the right direction.

from specification.

enrij avatar enrij commented on June 26, 2024

If i got it right your Book object is something like

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 Title property should be

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 

from specification.

jtrose22 avatar jtrose22 commented on June 26, 2024

@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:

public static ErrorOr<Title> Create(string title);

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.

Query.Where(x => ((string)(object)x.Title).Contains(filter)); <--- Works
Query.Search(x => x.Title.Value, filter); <--- Does not work

from specification.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.