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

IN Claus with Vogen (ValueObjects) types #852

Open
mkalinski93 opened this issue Nov 7, 2024 · 1 comment
Open

IN Claus with Vogen (ValueObjects) types #852

mkalinski93 opened this issue Nov 7, 2024 · 1 comment

Comments

@mkalinski93
Copy link

mkalinski93 commented Nov 7, 2024

Hey,

I´m using this project in combination with EntityFramework Core and Vogen. I came across one small issue that when I´m using a .Where statement with a value object created by Vogen, the "IN" method cannot be used as the type cannot be parsed.

For example:

I need to find records that are in a list of RecordId´s.
That type is generated by Vogen and is containing a Value field with a Guid.
In Vogen, you typically create instances like that:

RoleId id = RoleId.From(Guid value);

I´ve tried these expression but with no success.

// Fails as the type does not implement with "IConvertible"
options.Filter = "id in (Guid(\"532eaef3-16c8-4ef2-b19a-d4dc122f7f15\"))";
// Fails: "Operator '==' incompatible with operand types 'RoleId' and 'String'",
options.Filter = "id in (\"532eaef3-16c8-4ef2-b19a-d4dc122f7f15\")";
// Success
options.Filter = "id eq \"532eaef3-16c8-4ef2-b19a-d4dc122f7f15\"";

I know this case is very specific and absolutely not related to this library, but I would really like to get to know if there´s something I can do to make this possible.

@mkalinski93
Copy link
Author

mkalinski93 commented Nov 8, 2024

I´ve tested a few more scenarios and it seems that I have to explicitely use a typed collection for this case:

//This works, as the List is of type RoleId
List<RoleId> ids = new List<RoleId> { RoleId.Administrator, RoleId.Manager, RoleId.User };
var test = await customQuery.Where("Id in @0", ids).ToListAsync();
//This does not work
List<string> stringIds = ids.Select(x => x.Value.ToString()).ToList();
var test = await customQuery.Where("Id in @0", stringIds).ToListAsync();
System.InvalidOperationException: No generic method 'Contains' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. 
//This does not work
List<Guid> guidIds = ids.Select(x => x.Value).ToList();
var test = await customQuery.Where("Id in @0", guidIds).ToListAsync();
System.InvalidOperationException: No generic method 'Contains' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. 
//This does not work
List<object> objectIds = ids.Select(x => (object)x.Value).ToList();
var test = await customQuery.Where("Id in @0", objectIds).ToListAsync();
System.InvalidOperationException: No generic method 'Contains' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. 
//This does not work
string testString = string.Join(", ", ids.Select(x => $"Guid(\"{x.Value}\")"));
var test = await customQuery.Where("Id in @0", testString).ToListAsync();
System.InvalidOperationException: No generic method 'Contains' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. 

Since I´m using this library in order to filter my BackEnd from FrontEnd values, I don´t have any explicit type to set for the specify for the collection. But I´m struggling to find an answer that "Id eq 'key'" works, but "@0.Contains(Id) or Id IN (@0)" does not.

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

No branches or pull requests

1 participant