poweredsoft / dynamicquery Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hi
I have this scenario:
public class Product
{
public int id { get; set; }
public List<AttributeValue> lstAttributeValues { get; set; }
}
public class AttributeValue
{
public int productId { get; set; }
public string value { get; set; }
public int attributeId { get; set; }
public Attribute Attribute { get; set; }
}
public class Attribute
{
public int id { get; set; }
public string name { get; set; }
}
I wanted to add a feature to create a dynamic select. I am using the PoweredSoft.DynamicLinq library to add the select construct like so:
var select = ((IQueryable<TabArticoli>)queryable).Select(x =>
{
x.NullChecking(false);
x.DestinationType = typeof(Product);
filterSelect.Distinct().ToList().ForEach(y =>
{
x.Path(y);
});
});
filterSelect is a list of strings containing the Paths to filter. So far, so good. I can retrieve filtered data and also Product.lstAttributeValues but I can't access: lstAttributeValues.Attribute is always null.
I added the necessary includes:
queryable = ((IQueryable<Product>)queryable).Include(t => t.lstAttributeValues).ThenInclude(x=> x.Attribute);
if I delete the composition section of the select, the system is able to correctly retrieve Attribute as well. I can't understand what I'm doing wrong. I have tried several solutions including:
x.Path ("lstAttributeValues.Attribute");
but the system throws this exception:
at System.Linq.Expressions.Expression.Bind (MemberInfo member, Expression expression)
at PoweredSoft.DynamicLinq.Helpers.QueryableHelpers. <> c__DisplayClass2_0. <Select> b__1 (ValueTuple`2 t) in C: \ Luna \ DynamicLinq \ PoweredSoft.DynamicLinq \ Helpers \ QueryableHelpers.cs: line 173
at System.Linq.Enumerable.SelectListIterator`2.ToArray ()
at System.Linq.Enumerable.ToArray [TSource] (IEnumerable`1 source)
at PoweredSoft.DynamicLinq.Helpers.QueryableHelpers.Select (IQueryable query, List`1 parts, Type destinationType, Boolean nullChecking) in C: \ Luna \ DynamicLinq \ PoweredSoft.DynamicLinq \ Helpers \ QueryableHelpers.cs: line 162
at PoweredSoft.DynamicLinq.Fluent.SelectBuilder.Build () in C: \ Luna \ DynamicLinq \ PoweredSoft.DynamicLinq \ Fluent \ Select \ SelectBuilder.cs: line 107
at PoweredSoft.DynamicLinq.QueryableExtensions.Select (IQueryable query, Action`1 callback) in C: \ Luna \ DynamicLinq \ PoweredSoft.DynamicLinq \ Extensions \ QueryableExtensions.cs: line 117
at TooEasy.Articles.Infrastructure.DynamicIncludeStrategy.ArticlesStragetyInterceptor.InterceptIncludeStrategy (IQueryCriteria criteria, IQueryable`1 queryable) in C: \ Users \ lunat \ Source \ Repos \ TooEasy Web \ TooEasyWeb \ DynamicInfrastructure.Articles.Infrastructure.Articles. ArticlesStragetyInterceptor.cs: line 216
at PoweredSoft.DynamicQuery.QueryHandlerBase. <ApplyIncludeStrategyInterceptors> b__60_3 [TSource] (IQueryable`1 prev, IIncludeStrategyInterceptor`1 interceptor)
at System.Linq.Enumerable.Aggregate [TSource, TAccumulate] (IEnumerable`1 source, TAccumulate seed, Func`3 func)
at PoweredSoft.DynamicQuery.QueryHandlerBase.ApplyIncludeStrategyInterceptors [TSource] ()
at PoweredSoft.DynamicQuery.QueryHandlerBase.CommonBeforeExecute [TSource] ()
at PoweredSoft.DynamicQuery.QueryHandlerAsync.FinalExecuteAsync [TSource, TRecord] (CancellationToken cancellationToken)
at PoweredSoft.DynamicQuery.QueryHandlerAsync.ExecuteAsync [TSource] (IQueryable`1 queryable, IQueryCriteria criteria, IQueryExecutionOptions options, CancellationToken cancellationToken)
putting the projects in debug, I was able to understand that the system tries to associate Attribute field to the type IList of Attribute:
this line catch error
return Expression.Bind(typeToCreate.GetProperty(t.propertyName), t.expression);
and this there are
t.PropertyName: Attributo
t.expression -> t.ListOfAttributes.Select(Param_0 => Param_0.Attributo)
can you help me?
Will need to move json net support to a different package, and support both serialization and deserialization.
Hi everyone and thank you for your library. The only one who really helped me.
But I have a question for you.
If I had to select only a few fields based on the Includes that I do in the InterceptIncludeStrategy, what could I do?
Hi have this function for include the strategy
public IQueryable<Articles> InterceptIncludeStrategy(IQueryCriteria criteria,
IQueryable<Articles> queryable)
{
if(criteria.PageSize>=2000)
{
criteria.PageSize = 2000;
}
var lstFilters = new List<ISimpleFilter>();
criteria.Filters.ForEach(x =>
{
SimpleFilter filter = (SimpleFilter)x;
queryable = ((IQueryable<Articles>)queryable).Include(t => t.SameFields);
<--- CODE FOR INJECT FIELD SELECT
if (filter.Path.ToLower() == "include")
{
if (filter.Value.ToString().ToLower().Contains("images"))
{
queryable = ((IQueryable<Articles>)queryable).Include(t => t.Images);
<--- CODE FOR INJECT MORE OTHER FIELD SELECT
}
}
else
{
lstFilters.Add(filter);
}
});
criteria.Filters.Clear();
criteria.Filters.AddRange(lstFilters);
return queryable;
}
would like the portion of select fields to be added to each if. It's possible to do it?
thanks a lot I'm going crazy this these days
hi can we get a sample so we can learn from it, in ASP MVC or Core
Waiting for microsoft System.Text.Json v5.0 for interface deserialization.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.