Skip to content
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

How to use LinqKit in non static method? #197

Open
hanzllcc opened this issue Mar 16, 2024 · 0 comments
Open

How to use LinqKit in non static method? #197

hanzllcc opened this issue Mar 16, 2024 · 0 comments

Comments

@hanzllcc
Copy link

hanzllcc commented Mar 16, 2024

I have the IdentificationType class:

public sealed record IdentificationType
{
        public int Id { get; }
	public string Alias { get; }

	private IdentificationType(int id, string alias)
	{
                this.Id = id;
		this.Alias = alias;
	}

	public bool Equals(IdentificationType? left) => this.Alias == left?.Alias;

	public override int GetHashCode() => this.Alias.GetHashCode();
}

The property Alias is configured as Alternate key, and the Id as Primary key.
I want to use the Equals method in Ef core, in this way:

public Task<IdentificationType?> Find(IdentificationType identificationType) 
{
    return dbContext.IdentificationType
                    .AsExpandableEFCore()
                    .SingleOrDefaultAsync(i => i.Equals(identificationType));
}

When the Find method is invoked, Ef core uses Id instead of Alias.
How I could configure LinqKit to expand the Equals method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant