logo
down
shadow

How to conditionally select item from hashset with queryable linq?


How to conditionally select item from hashset with queryable linq?

Content Index :

How to conditionally select item from hashset with queryable linq?
Tag : chash , By : enginecrew
Date : November 24 2020, 03:01 PM

will be helpful for those in need You want to create an Expression that can be used to filter your collection of Customers.
Your error is that the signature of your expression is not correct.
Expression<Func<TSource, bool>> expr = ...
InMemorySet<Customer> customerCollection = new InMemorySet<Customer>();
IQueryable<Customer> customers = customerCollection;
IQueryable<Cusomter> xxCustomers = customers.Where(customer => customer.Name == XX);
string XX = ...
Expression<Func<Customer, bool>> expr = customer => customer.Name == XX;
IQueryable<Customer> result1 = customers.Where(expr);
// (2) Use the Provider
IQueryProvider provider = customers.Provider;
object query2 = provider.Execute(customers.Expression)

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

LINQ: Expression.Call(typeof(Queryable), "Select"


Tag : development , By : Angelo Giannatos
Date : March 29 2020, 07:55 AM
should help you out I was looking more for how to do this using Expressions (correct terminology?) and I did eventually figure it out.
I had to change this:
IQueryable<ChildEntity> list = new List<ChildEtity>().AsQueryable(); 
Expression _selectExpression = Expression.Call( 
  typeof(Queryable), 
  "Select", 
  new Type[] { typeof(ChildEntity), typeof(ChildEntityProjection) }, 
  Expression.Constant(list), 
  _nestedLambda); 
MethodInfo selectMethod = null;
foreach (MethodInfo m in typeof(Enumerable).GetMethods().Where(m => m.Name == "Select"))
  foreach (ParameterInfo p in m.GetParameters().Where(p => p.Name.Equals("selector")))
    if (p.ParameterType.GetGenericArguments().Count() == 2)
      selectMethod = (MethodInfo)p.Member;

var _selectExpression = Expression.Call(
  null,
  selectMethod.MakeGenericMethod(new Type[] { typeof(ChildEntity), typeof(ChildEntityProjection) }),
  new Expression[] { _myPropertyExpression, _myFuncExpression });

Invoking HashSet.Add(item) in Linq vs foreach loop


Tag : chash , By : Thaweesak Suksuwan
Date : March 29 2020, 07:55 AM
may help you . You Select it, but don't do anything with the result. Because of LINQ's lazy evaluation (it generates the results on-demand through an IEnumerable) it just won't get executed. Use the foreach loop, it's the cleanest possible solution.
(The other solution is to use a List instead and call ForEach on that... but unless you have a really good reason for wanting to use a method with a callback, there's no advantage.)
customers.UnionWith(innerCustomers);

Dynamic LINQ, Select function, works on Enumerable, but not Queryable


Tag : chash , By : RichAA
Date : March 29 2020, 07:55 AM
hop of those help? The problem is that LineItems is an ICollection, while the first parameter to Queryable.Select requires an IQueryable. ICollection only implements IEnumerable which is why it works for Enumerable.Select.
You will need to change the type of expr to be IQueryable.
public static Expression<Func<decimal?>> CreateSumLineItemsExpr(Document document)
{
    var docExpr = Expression.Constant(document);
    var itemsExpr = Expression.Property(docExpr, "LineItems");

    Expression<Func<LineItem, decimal?>> selector = i => i.Credit;
    var queryableExpr = Expression.Call(typeof(Queryable), "AsQueryable", new[] { typeof(LineItem) }, itemsExpr);
    var selectExpr = Expression.Call(typeof(Queryable), "Select", new[] { typeof(LineItem), typeof(decimal?) }, queryableExpr, selector);
    var sumExpr = Expression.Call(typeof(Queryable), "Sum", null, selectExpr);

    return Expression.Lambda<Func<decimal?>>(sumExpr);
}

Linq Where then Select on a HashSet


Tag : chash , By : Nick
Date : March 29 2020, 07:55 AM
I wish this help you Your query returns an enumerable that corresponds to all your products, each item of that enumerable is an enumerable itself, containing zero or more categories with ID of 35.
You can change your query to get only products that have category 35 in them:
var products = repo
    .GetAll()
    .Where(p => p.CategoryProducts.Any(c => c.CategoryId == 35));

How can i convert linq in queryable select?


Tag : chash , By : simonth
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I have this select new LINQ query : , Not sure what you exactly need. But maybe it is something like this?
var listaClienti=contestoDB.Clienti.AsQueryable()
.Where(c=>c.Cognome.Contains(nominativoDaCercare) || c.Cognome == nominativoDaCercare || c.Cognome.StartsWith(nominativoDaCercare) || c.Nome.Contains(nominativoDaCercare) || c.Nome == nominativoDaCercare || c.Nome.StartsWith(nominativoDaCercare))
.Select(c=>new
    {
        IDCliente = c.ID,
            Cliente = c.Nome + " " + c.Cognome,
            Indirizzo = c.Indirizzo,
            Telefono = c.Telefono,
            CodiceFiscale = c.CodiceFiscale,
            PartitaIva = c.PartitaIva,
            NumeroVeicoli = f.CalcolaNumeroVeicoli(c.ID)
    });
Related Posts Related QUESTIONS :
  • Numeric Data Entry in WPF
  • Print a Winform/visual element
  • C# logic order and compiler behavior
  • When to use an extension method with lambda over LINQtoObjects to filter a collection?
  • How to make a button appear as if it is pressed?
  • C# and Arrow Keys
  • How do you resolve a domain name to an IP address with .NET/C#?
  • Should the folders in a solution match the namespace?
  • How can I evaluate C# code dynamically?
  • CSharpCodeProvider Compilation Performance
  • How can I create Prototype Methods (like JavaScript) in C#.Net?
  • DataTable Loop Performance Comparison
  • CSV string handling
  • What is the best way to do unit testing for ASP.NET 2.0 web pages?
  • High availability
  • What to use for Messaging with C#
  • Accessing a Dictionary.Keys Key through a numeric index
  • ConfigurationManager.AppSettings Performance Concerns
  • What Are Some Good .NET Profilers?
  • Is this a good way to determine OS Architecture?
  • How to create a tree-view preferences dialog type of interface in C#?
  • Searching directories for tons of files?
  • Can I have a method returning IEnumerator<T> and use it in a foreach loop?
  • Why can't I have abstract static methods in C#?
  • Displaying ad content from Respose.WriteFile()/ Response.ContentType
  • Convert integers to written numbers
  • Absolute path back to web-relative path
  • How can we generate getters and setters in Visual Studio?
  • Bringing Window to the Front in C# using Win32 API
  • Possible to "spin off" several GUI threads? (Not halting the system at Application.Run)
  • Reading a C/C++ data structure in C# from a byte array
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com