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 in result dto object instead of db class #394
Comments
If I got it right, specification and EF Core should handle your request already: // Assuming Material having a property Type of type MaterialType
internal sealed class MaterialByMaterialTypeNameSpecification : Specification<Material>
{
internal MaterialByMaterialTypeNameSpecification(string name)
{
// Deal with an empty name
ArgumentException.ThrowIfNullOrEmpty(name);
Query.Where(material => material.Type.Name == name)
}
}
// Somewhere in your code
{
private readonly IRepositoryBase<Material> _repository;
// ...
public void Bar(CancellationToken cancellationToken = default)
{
var specification = new MaterialByMaterialTypeNameSpecification("Foo");
List<Material> materials = await _repository.ListAsync(specification, cancellationToken);
// Do something with the returned materials
}
} |
Hi Thank you for answer. But my question is somehow different. Let me explain. I have MachineDto which is also include Machine group And MachineGroup Class. When i retrivening Machine data including MachineGroup and convert to MachineDto, finally show on table for user. And I already implemented Pagination. when user try to search MAchineGroupName in the table, serach function is try to search in machine table. On the machine table hasnt machinegroup name in db table. So that How can i implmemnt this request by using ardalis.specifiacation?
> public class MachineDto : IDto
> {
> public Guid Id { get; set; }
> public string Name { get; set; } = default!;
> public Guid MachineGroupId { get; set; }
> public string MachineGroupName { get; set; } = default!;
> public string EquipmentNo{ get; set; } = default!;
> }
>
> public class MachineGroup
> {
> public Guid Id { get; set; }
> public string Name { get; set; } = default!;
>
> }
> If I got it right, specification and EF Core should handle your request already:
>
> ```cs
> // Assuming Material having a property Type of type MaterialType
>
> internal sealed class MaterialByMaterialTypeNameSpecification : Specification<Material>
> {
> internal MaterialByMaterialTypeNameSpecification(string name)
> {
> // Deal with an empty name
> ArgumentException.ThrowIfNullOrEmpty(name);
>
> Query.Where(material => material.Type.Name == name)
> }
> }
>
> // Somewhere in your code
> {
> private readonly IRepositoryBase<Material> _repository;
>
> // ...
>
> public void Bar(CancellationToken cancellationToken = default)
> {
> var specification = new MaterialByMaterialTypeNameSpecification("Foo");
> List<Material> materials = await _repository.ListAsync(specification, cancellationToken);
> // Do something with the returned materials
> }
> }
> ``` |
Hi... I'm afraid but I don't understand what you are looking for... In addition there is no I'd love to help but provide the complete code (regarding the issue, obviously) or a PoC repo |
Ok. I will provide a repo tomorrow .
Thank you very much
iOS için Outlook<https://aka.ms/o0ukef> uygulamasını edinin
…________________________________
Gönderen: Enrico Barbieri ***@***.***>
Gönderildi: Wednesday, May 22, 2024 6:44:06 PM
Kime: ardalis/Specification ***@***.***>
Bilgi: ertugrulkaya ***@***.***>; Author ***@***.***>
Konu: Re: [ardalis/Specification] Search in result dto object instead of db class (Issue #394)
Hi...
I'm afraid but I don't understand what you are looking for... In addition there is no SearchBy property nor method in Query property of Specification so I assume you have some extension methods somewhere...
I'd love to help but provide the complete code (regarding the issue, obviously) or a PoC repo
—
Reply to this email directly, view it on GitHub<#394 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEBU57PQGPJ34IW4B3IKNZTZDS4MNAVCNFSM6AAAAABG4HW65CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRVGEZDANBYGY>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Search option in result dto object instead of db class.
I have 3 classes; Material , Material Type and Material Group.
Material includes the material type and material group.
When I show list of materials including material type name to clients , client want search material type name ?
But this filed is not in same db table.
How we can do it ? What is the best case ?
The text was updated successfully, but these errors were encountered: