c# - Lambda expression for querying an array of KeyValuePairs using Expression<Func> -
I have such kind of valuepayers:
keyvaluePair & lt; Long, int & gt; [ ] order items; The 'long' component of this key value corresponds to an ID (primary key) value on the database table.
Using the unit framework, I have defined a repository that provides the following method on its interface:
IEnumerable The above repository method allows me to query the database using lambda expressions. For example, if I want to query the database for all rows, where 'category' Columns are equal to 'cameras', so I can say:
var results = repository GetMany (a => a. Category.Contains ("camera")) ToList () .; What I want to query is all the rows where the key (primary key) is equal to key value from any element of the array of value value piids. So if the list of KiwilPayers is a list of product IDs and their quantity, then I just want to query the database for all those products whose ID is in my array.
Can someone try an appropriate lambda expression?
* Edit the original Tips for use:
var results = repository GetMany (a => keys. Any (x => x == a.Id)). ToList (); Is a good and if I am creating an array of keys from the first keyValuePair array, then it will work. So something like this: tall [] pids = new long [orderItems.Length]; For (Int i = 0; I & lt; Order I.Languety; I ++) {Peds [0] = Order I [A]. KA; } Var Product = Product Repository.GetManay (A = & gt; Pids.Any (x => x == a.Id)). ToList (); This indicates that 'any' section is supported by EF. I still can not get it to work though without using this long time array. Quality for any kind of quality which is not enough to give to a solution, for which I do not need to extract the 'key' value from KeyWellPear first in the array.
If I use the keys. Anyone I get the following exception:
Unable to prepare the "continuous price type" system.Collections.Generic.inInMerebell '1'. Only the primitive type (for example, int 32, string and guide ) Are supported in this context "
It is difficult to use the GetMany-Method It works with the database in this case. But you should have a query-object in the name of your institutions - I take categories (a type of query object with field / asset ID) as a category here. Then you can do this:
var query = context.Categories; Forchach (wer pair in order items) query = query Union (context where (categorization => categorie.Id = pair.Key)); and finally using the query:
var result = query. ToList (); PS: To use it with your repository pattern, you can only display this query-store as an IQueryable within your repository interface (or for example your generic You can create a legacy interface from the repository ICategoryRepository)
Comments
Post a Comment