├── PoweredSoft.DynamicLinq.Test
├── App.config
├── GetCoreContext.cs
├── CountTests.cs
├── PoweredSoft.DynamicLinq.Test.csproj
├── AnonymousTypeTest.cs
├── Helpers
│ └── QueryableAssert.cs
├── InTests.cs
├── ConstantTests.cs
├── HelpersTests.cs
├── ComplexQueriesTests.cs
├── StringComparision.cs
├── EntityFrameworkTests.cs
├── SimpleQueriesTest.cs
├── TestData.cs
├── EntityFrameworkCoreTests.cs
├── SelectTests.cs
├── ShortcutTests.cs
└── GroupingTests.cs
├── PoweredSoft.DynamicLinq.Dal
├── packages.config
├── Pocos
│ ├── Uniqe.cs
│ ├── Website.cs
│ ├── CommentLike.cs
│ ├── Author.cs
│ ├── Comment.cs
│ └── Post.cs
├── BlogCoreContext.cs
├── PoweredSoft.DynamicLinq.Dal.csproj
├── App.config
├── BlogContext.cs
└── Configurations
│ └── Configurations.cs
├── PoweredSoft.DynamicLinq
├── Interfaces
│ └── IQueryBuilder.cs
├── Fluent
│ ├── OrderBy
│ │ ├── OrderByPart.cs
│ │ └── OrderByBuilder.cs
│ ├── Where
│ │ ├── WhereBuilderCondition.cs
│ │ ├── WhereBuilder.cs
│ │ └── WhereBuilder.shortcuts.cs
│ ├── Group
│ │ └── GroupBuilder.cs
│ └── Select
│ │ └── SelectBuilder.cs
├── Properties
│ └── PublishProfiles
│ │ └── FolderProfile.pubxml
├── Parser
│ ├── ExpressionParserPiece.cs
│ ├── ExpressionParserPieceGroup.cs
│ ├── ParserExtensions.cs
│ └── ExpressionParser.cs
├── PoweredSoft.DynamicLinq.csproj
├── Constants.cs
├── Extensions
│ ├── EnumerableExtensions.cs
│ └── QueryableExtensions.cs
├── Helpers
│ └── TypeHelpers.cs
├── DynamicType
│ └── DynamicClass.cs
└── Resolver
│ └── PathExpressionResolver.cs
├── PoweredSoft.DynamicLinq.EntityFramework
├── App.config
├── Extensions
│ └── DbContextExtensions.cs
└── PoweredSoft.DynamicLinq.EntityFramework.csproj
├── LICENSE
├── PoweredSoft.DynamicLinq.EntityFrameworkCore
├── PoweredSoft.DynamicLinq.EntityFrameworkCore.csproj
└── Extensions
│ └── DbContextExtensions.cs
├── .gitattributes
├── PoweredSoft.DynamicLinq.sln
├── .gitignore
└── README.md
/PoweredSoft.DynamicLinq.Test/App.config:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Test/GetCoreContext.cs:
--------------------------------------------------------------------------------
1 | namespace PoweredSoft.DynamicLinq.Test
2 | {
3 | internal class GetCoreContext
4 | {
5 | private string v;
6 |
7 | public GetCoreContext(string v)
8 | {
9 | this.v = v;
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Interfaces/IQueryBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace PoweredSoft.DynamicLinq
7 | {
8 | public interface IQueryBuilder
9 | {
10 | IQueryable Query { get; }
11 |
12 | IQueryable Build();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/Pocos/Uniqe.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PoweredSoft.DynamicLinq.Dal.Pocos
8 | {
9 | public class Unique
10 | {
11 | public long Id { get; set; }
12 | public Guid RowNumber { get; set; }
13 | public Guid? OtherNullableGuid { get; set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/Pocos/Website.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PoweredSoft.DynamicLinq.Dal.Pocos
8 | {
9 | public class Website
10 | {
11 | public long Id { get; set; }
12 | public string Url { get; set; }
13 | public string Title { get; set; }
14 |
15 | public ICollection Authors { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Fluent/OrderBy/OrderByPart.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PoweredSoft.DynamicLinq.Fluent
8 | {
9 | public class OrderByPart
10 | {
11 | public string Path { get; set; }
12 |
13 | public QueryOrderByDirection Direction { get; set; } = QueryOrderByDirection.Ascending;
14 |
15 | public bool Append { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/Pocos/CommentLike.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PoweredSoft.DynamicLinq.Dal.Pocos
8 | {
9 | public class CommentLike
10 | {
11 | public long Id { get; set; }
12 | public long CommentId { get; set; }
13 | public DateTimeOffset CreateTime { get; set; }
14 |
15 | public virtual Comment Comment { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Properties/PublishProfiles/FolderProfile.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | FileSystem
8 | Release
9 | Any CPU
10 | netstandard2.0
11 | bin\Release\netstandard2.0\publish\
12 |
13 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/Pocos/Author.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PoweredSoft.DynamicLinq.Dal.Pocos
8 | {
9 | public class Author
10 | {
11 | public long Id { get; set; }
12 | public string FirstName { get; set; }
13 | public string LastName { get; set; }
14 | public long? WebsiteId { get; set; }
15 |
16 | public virtual Website Website { get; set; }
17 | public ICollection Posts { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/Pocos/Comment.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PoweredSoft.DynamicLinq.Dal.Pocos
8 | {
9 | public class Comment
10 | {
11 | public long Id { get; set; }
12 | public long PostId { get; set; }
13 | public string DisplayName { get; set; }
14 | public string Email { get; set; }
15 | public string CommentText { get; set; }
16 | public Post Post { get; set; }
17 | public ICollection CommentLikes { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Parser/ExpressionParserPiece.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace PoweredSoft.DynamicLinq.Parser
4 | {
5 | public class ExpressionParserPiece
6 | {
7 | public Type Type { get; set; }
8 | public bool IsGenericEnumerable { get; set; }
9 | public Type EnumerableType { get; set; }
10 | public ExpressionParserPiece Parent { get; set; }
11 | public string Name { get; internal set; }
12 |
13 | #if DEBUG
14 | public string DebugPath => $"{Type?.Name} {Name} -> {Parent?.DebugPath ?? "ROOT PARAMETER"}";
15 | public override string ToString() => $"{Type?.Name} {Name}";
16 | #endif
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/BlogCoreContext.cs:
--------------------------------------------------------------------------------
1 | using PoweredSoft.DynamicLinq.Dal.Pocos;
2 | using Microsoft.EntityFrameworkCore;
3 | using JetBrains.Annotations;
4 | using System.Diagnostics.CodeAnalysis;
5 |
6 | namespace PoweredSoft.DynamicLinq.Dal
7 | {
8 | public class BlogCoreContext : DbContext
9 | {
10 | public BlogCoreContext([NotNull] DbContextOptions options) : base(options)
11 | {
12 | }
13 |
14 | protected BlogCoreContext()
15 | {
16 | }
17 |
18 | public DbSet Authors { get; set; }
19 | public DbSet Comments { get; set; }
20 | public DbSet Posts { get; set; }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/Pocos/Post.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PoweredSoft.DynamicLinq.Dal.Pocos
8 | {
9 | public class Post
10 | {
11 | public long Id { get; set; }
12 | public long AuthorId { get; set; }
13 | public string Title { get; set; }
14 | public string Content { get; set; }
15 | public DateTimeOffset CreateTime { get; set; }
16 | public DateTimeOffset? PublishTime { get; set; }
17 |
18 | public Author Author { get; set; }
19 | public virtual ICollection Comments { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/PoweredSoft.DynamicLinq.Dal.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Parser/ExpressionParserPieceGroup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using System.Text;
6 |
7 | namespace PoweredSoft.DynamicLinq.Parser
8 | {
9 | public class ExpressionParserPieceGroup
10 | {
11 | public List Pieces { get; set; } = new List();
12 | public ParameterExpression Parameter { get; set; }
13 | public ExpressionParserPieceGroup Parent { get; set; }
14 |
15 | #if DEBUG
16 | public override string ToString() => $"{Parameter?.ToString()} is {Parameter?.Type} | {(Pieces == null ? "" : string.Join(" -> ", Pieces.Select(t2 => t2.ToString())))}";
17 | #endif
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Fluent/Where/WhereBuilderCondition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace PoweredSoft.DynamicLinq.Fluent
8 | {
9 | public class WhereBuilderCondition
10 | {
11 | public string Path { get; set; }
12 | public ConditionOperators ConditionOperator { get; set; }
13 | public object Value { get; set; }
14 | public bool And { get; set; }
15 | public QueryConvertStrategy ConvertStrategy { get; set; }
16 | public List Conditions { get; set; } = new List();
17 | public QueryCollectionHandling CollectionHandling { get; set; }
18 | public StringComparison? StringComparisation { get; set; } = null;
19 | public bool Negate { get; set; } = false;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.EntityFramework/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Test/CountTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using Microsoft.VisualStudio.TestTools.UnitTesting;
4 |
5 | namespace PoweredSoft.DynamicLinq.Test
6 | {
7 | [TestClass]
8 | public class CountTests
9 | {
10 | [TestMethod]
11 | public void Count()
12 | {
13 | var normalSyntax = TestData.Sales.Count();
14 | var nonGenericQueryable = (IQueryable)TestData.Sales.AsQueryable();
15 | var dynamicSyntax = nonGenericQueryable.Count();
16 | Assert.AreEqual(normalSyntax, dynamicSyntax);
17 | }
18 |
19 | [TestMethod]
20 | public void LongCount()
21 | {
22 | var normalSyntax = TestData.Sales.LongCount();
23 | var nonGenericQueryable = (IQueryable)TestData.Sales.AsQueryable();
24 | var dynamicSyntax = nonGenericQueryable.LongCount();
25 | Assert.AreEqual(normalSyntax, dynamicSyntax);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Powered Softwares Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Test/PoweredSoft.DynamicLinq.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Parser/ParserExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using System.Text;
6 |
7 | namespace PoweredSoft.DynamicLinq.Parser
8 | {
9 | public static class ParserExtensions
10 | {
11 | public static ExpressionParserPiece FirstEnumerableParent(this ExpressionParserPiece piece)
12 | {
13 | var result = ExpressionParser.GetFirstEnumerableParent(piece);
14 | return result;
15 | }
16 |
17 |
18 |
19 | public static Type GroupEnumerableType(this ExpressionParserPieceGroup group)
20 | {
21 | return group.Pieces.Last().EnumerableType;
22 | }
23 |
24 | public static Type ResolveNullHandlingType(this List groups)
25 | {
26 | if (groups.Count() == 1)
27 | {
28 | return groups.First().Pieces.Last().Type;
29 | }
30 |
31 | var type = groups.Last().Pieces.Last().Type;
32 | return typeof(IEnumerable<>).MakeGenericType(type);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Test/AnonymousTypeTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Microsoft.VisualStudio.TestTools.UnitTesting;
4 | using PoweredSoft.DynamicLinq.DynamicType;
5 |
6 | namespace PoweredSoft.DynamicLinq.Test
7 | {
8 | [TestClass]
9 | public class AnonymousTypeTest
10 | {
11 | [TestMethod]
12 | public void TestEqual()
13 | {
14 | var properties = new List<(Type type, string propertyName)>()
15 | {
16 | (typeof(int), "Id"),
17 | (typeof(string), "FirstName"),
18 | (typeof(string), "LastName")
19 | };
20 |
21 | var type = DynamicClassFactory.CreateType(properties);
22 | var instanceA = Activator.CreateInstance(type) as DynamicClass;
23 | var instanceB = Activator.CreateInstance(type) as DynamicClass;
24 |
25 | instanceA.SetDynamicPropertyValue("Id", 1);
26 | instanceA.SetDynamicPropertyValue("FirstName", "David");
27 | instanceA.SetDynamicPropertyValue("LastName", "Lebee");
28 |
29 | instanceB.SetDynamicPropertyValue("Id", 1);
30 | instanceB.SetDynamicPropertyValue("FirstName", "David");
31 | instanceB.SetDynamicPropertyValue("LastName", "Lebee");
32 |
33 | Assert.IsTrue(instanceA.Equals(instanceB));
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.EntityFramework/Extensions/DbContextExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.Entity;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using PoweredSoft.DynamicLinq.Fluent;
9 |
10 | namespace PoweredSoft.DynamicLinq.EntityFramework
11 | {
12 | public static class DbContextExtensions
13 | {
14 | public static IQueryable Query(this DbContext context, Type pocoType, Action callback)
15 | {
16 | var set = context.Set(pocoType);
17 | var queryable = set.AsQueryable();
18 | var builder = new WhereBuilder(queryable);
19 | callback(builder);
20 | var result = builder.Build();
21 | return result;
22 | }
23 |
24 | public static IQueryable Query(this DbContext context, Action callback)
25 | where T : class
26 | {
27 | var query = context.Set().AsQueryable();
28 | query = query.Query(callback);
29 | return query;
30 | }
31 |
32 | public static IQueryable Where(this DbContext context, Type pocoType, Action callback)
33 | => context.Query(pocoType, callback);
34 |
35 | public static IQueryable Where(this DbContext context, Action callback)
36 | where T : class => context.Query(callback);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.EntityFrameworkCore/PoweredSoft.DynamicLinq.EntityFrameworkCore.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 | True
6 | David Lebee
7 | Powered Software Inc.
8 | Entity Framework extensions for Dynamic Linq of PoweredSoft
9 | github
10 | https://github.com/PoweredSoft/DynamicLinq
11 | entity framework core efcore ef dynamic linq
12 | https://github.com/PoweredSoft/DynamicLinq
13 | https://secure.gravatar.com/avatar/4e32f73820c16718909a06c2927f1f8b?s=512&r=g&d=retro
14 | 1.1.0$(VersionSuffix)
15 | EF Integration of DynamicLinq
16 | PoweredSoft.DynamicLinq.EntityFrameworkCore
17 | First Release of efcore extensions
18 | False
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/BlogContext.cs:
--------------------------------------------------------------------------------
1 | using PoweredSoft.DynamicLinq.Dal.Configurations;
2 | using PoweredSoft.DynamicLinq.Dal.Pocos;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Data.Entity;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace PoweredSoft.DynamicLinq.Dal
11 | {
12 |
13 | public class BlogContext : DbContext
14 | {
15 | public DbSet Authors { get; set; }
16 | public DbSet Comments { get; set; }
17 | public DbSet Posts { get; set; }
18 |
19 | static BlogContext()
20 | {
21 | Database.SetInitializer(new DropCreateDatabaseAlways());
22 | }
23 |
24 | public BlogContext()
25 | {
26 |
27 | }
28 |
29 | public BlogContext(string connectionString) : base(connectionString)
30 | {
31 |
32 | }
33 |
34 | protected override void OnModelCreating(DbModelBuilder modelBuilder)
35 | {
36 | base.OnModelCreating(modelBuilder);
37 | modelBuilder.Configurations.Add(new AuthorConfiguration());
38 | modelBuilder.Configurations.Add(new CommentConfiguration());
39 | modelBuilder.Configurations.Add(new PostConfiguration());
40 | modelBuilder.Configurations.Add(new WebsiteConfiguration());
41 | modelBuilder.Configurations.Add(new CommentLikeConfiguration());
42 | modelBuilder.Configurations.Add(new UniqueConfiguration());
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/PoweredSoft.DynamicLinq.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | True
6 | Powered Softwares Inc.
7 | David Lebée
8 |
9 | DynamicLinq by PoweredSoft
10 | Allows users to make dynamic query over a IQueryable<T>
11 | https://github.com/PoweredSoft/DynamicLinq
12 | https://secure.gravatar.com/avatar/4e32f73820c16718909a06c2927f1f8b?s=512&r=g&d=retro
13 | github
14 | dynamic linq queryable
15 | 1.1.0$(VersionSuffix)
16 | https://github.com/PoweredSoft/DynamicLinq
17 | PoweredSoft.DynamicLinq
18 | Added not contains thanks to Jon-Galloway.
19 | Added negate parameter to allow negating any conditions.
20 | False
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.EntityFramework/PoweredSoft.DynamicLinq.EntityFramework.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1;net461
5 | True
6 | David Lebee
7 | Powered Software Inc.
8 | Entity Framework extensions for Dynamic Linq of PoweredSoft
9 | github
10 | https://github.com/PoweredSoft/DynamicLinq
11 | entity framework ef dynamic linq
12 | https://github.com/PoweredSoft/DynamicLinq
13 | https://secure.gravatar.com/avatar/4e32f73820c16718909a06c2927f1f8b?s=512&r=g&d=retro
14 | 1.1.0$(VersionSuffix)
15 | EF Integration of DynamicLinq
16 | PoweredSoft.DynamicLinq.EntityFramework
17 | Added Negate & NotContains
18 | False
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.EntityFrameworkCore/Extensions/DbContextExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Microsoft.EntityFrameworkCore;
8 | using PoweredSoft.DynamicLinq.Fluent;
9 |
10 | namespace PoweredSoft.DynamicLinq.EntityFrameworkCore
11 | {
12 | public static class DbContextExtensions
13 | {
14 | private static MethodInfo SetMethod = typeof(DbContext).GetMethod(nameof(DbContext.Set), BindingFlags.Public | BindingFlags.Instance);
15 |
16 | public static IQueryable Query(this DbContext context, Type pocoType, Action callback)
17 | {
18 | var set = SetMethod.MakeGenericMethod(pocoType).Invoke(context, new object[] { });
19 | var queryable = set as IQueryable;
20 | var builder = new WhereBuilder(queryable);
21 | callback(builder);
22 | var result = builder.Build();
23 | return result;
24 | }
25 |
26 | public static IQueryable Query(this DbContext context, Action callback)
27 | where T : class
28 | {
29 | var query = context.Set().AsQueryable();
30 | query = query.Query(callback);
31 | return query;
32 | }
33 |
34 | public static IQueryable Where(this DbContext context, Type pocoType, Action callback)
35 | => context.Query(pocoType, callback);
36 |
37 | public static IQueryable Where(this DbContext context, Action callback)
38 | where T : class => context.Query(callback);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Test/Helpers/QueryableAssert.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace PoweredSoft.DynamicLinq.Test.Helpers
9 | {
10 | public static class QueryableAssert
11 | {
12 | private static bool _sameList(IQueryable a, IQueryable b)
13 | where T : class
14 | {
15 | if (a.Count() != b.Count())
16 | return false;
17 |
18 | var listA = a.ToList();
19 | var listB = b.ToList();
20 | for (var i = 0; i < listA.Count; i++)
21 | {
22 | if (listA.ElementAt(i) != listB.ElementAt(i))
23 | return false;
24 | }
25 |
26 | return true;
27 | }
28 |
29 | public static void AreEqual(IQueryable a, IQueryable b)
30 | where T : class
31 | {
32 | Assert.IsTrue(_sameList(a, b));
33 | }
34 |
35 | public static void AreNotEqual(IQueryable a, IQueryable b)
36 | where T : class
37 | {
38 | Assert.IsFalse(_sameList(a, b));
39 | }
40 |
41 | public static void AreEqual(IQueryable a, IQueryable b, string message)
42 | where T : class
43 | {
44 | Assert.IsTrue(_sameList(a, b), message);
45 | }
46 |
47 | public static void AreNotEqual(IQueryable a, IQueryable b, string message)
48 | where T : class
49 | {
50 | Assert.IsFalse(_sameList(a, b), message);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Fluent/OrderBy/OrderByBuilder.cs:
--------------------------------------------------------------------------------
1 | using PoweredSoft.DynamicLinq.Helpers;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace PoweredSoft.DynamicLinq.Fluent
8 | {
9 | public class OrderByBuilder : IQueryBuilder
10 | {
11 | public IQueryable Query { get; }
12 |
13 | public OrderByBuilder(IQueryable query)
14 | {
15 | Query = query;
16 | }
17 |
18 | public virtual IQueryable Build()
19 | {
20 | var query = Query;
21 |
22 | Sorts.ForEach(sort =>
23 | {
24 | query = QueryableHelpers.CreateOrderByExpression(query, sort.Path, sort.Direction, sort.Append);
25 | });
26 |
27 | return query;
28 | }
29 |
30 | public List Sorts { get; protected set; } = new List();
31 |
32 | public virtual OrderByBuilder OrderBy(string path, QueryOrderByDirection direction, bool append)
33 | {
34 | if (append == false)
35 | Sorts.Clear();
36 |
37 | Sorts.Add(new OrderByPart
38 | {
39 | Path = path,
40 | Direction = direction,
41 | Append = append
42 | });
43 | return this;
44 | }
45 |
46 | #region shortcuts
47 | public virtual OrderByBuilder OrderBy(string path)
48 | => OrderBy(path, QueryOrderByDirection.Ascending, false);
49 |
50 | public virtual OrderByBuilder OrderByDescending(string path)
51 | => OrderBy(path, QueryOrderByDirection.Descending, false);
52 |
53 | public virtual OrderByBuilder ThenBy(string path)
54 | => OrderBy(path, QueryOrderByDirection.Ascending, true);
55 |
56 | public virtual OrderByBuilder ThenByDescending(string path)
57 | => OrderBy(path, QueryOrderByDirection.Descending, true);
58 | #endregion
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Fluent/Group/GroupBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Linq;
5 | using PoweredSoft.DynamicLinq.Helpers;
6 |
7 | namespace PoweredSoft.DynamicLinq.Fluent
8 | {
9 | public class GroupBuilder : IQueryBuilder
10 | {
11 | public List<(string path, string propertyName)> Parts { get; set; } = new List<(string path, string propertyName)>();
12 | public Type Type { get; set; }
13 | public bool Empty => !Parts.Any();
14 | public Type EqualityComparerType { get; set; }
15 |
16 | public IQueryable Query { get; protected set; }
17 |
18 | public bool IsNullCheckingEnabled { get; protected set; } = false;
19 |
20 | public GroupBuilder(IQueryable query)
21 | {
22 | Query = query;
23 | }
24 |
25 | public GroupBuilder Path(string path, string propertyName = null)
26 | {
27 | if (propertyName == null)
28 | {
29 | var name = path;
30 | if (name.Contains("."))
31 | {
32 | var parts = name.Split('.');
33 | name = parts[parts.Length - 1]; // the last one.
34 | }
35 |
36 | if (Parts.Any(t => t.propertyName == name))
37 | throw new Exception($"{name} is already taken by another group part, you can specify a property name instead to resolve this issue");
38 |
39 | propertyName = name;
40 | }
41 |
42 | Parts.Add((path, propertyName));
43 | return this;
44 | }
45 |
46 | public GroupBuilder NullChecking(bool nullChecking = true)
47 | {
48 | IsNullCheckingEnabled = nullChecking;
49 | return this;
50 | }
51 |
52 | public GroupBuilder UseType(Type type)
53 | {
54 | Type = type;
55 | return this;
56 | }
57 |
58 | public GroupBuilder EqualityComparer(Type type)
59 | {
60 | EqualityComparerType = type;
61 | return this;
62 | }
63 |
64 | public virtual IQueryable Build()
65 | {
66 | if (Empty)
67 | throw new Exception("No group specified, please specify at least one group");
68 |
69 | var ret = QueryableHelpers.GroupBy(Query, Query.ElementType, Parts, groupToType: Type, equalityCompareType: EqualityComparerType, nullChecking: IsNullCheckingEnabled);
70 | return ret;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Test/InTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
5 | using PoweredSoft.DynamicLinq;
6 | using PoweredSoft.DynamicLinq.Dal.Pocos;
7 | using PoweredSoft.DynamicLinq.Test.Helpers;
8 |
9 | namespace PoweredSoft.DynamicLinq.Test
10 | {
11 | [TestClass]
12 | public class InTests
13 | {
14 | [TestMethod]
15 | public void In()
16 | {
17 | IQueryable a, b;
18 | var ageGroup = new List() { 28, 27, 50 };
19 | a = TestData.Persons.AsQueryable().Query(t => t.In("Age", ageGroup));
20 | b = TestData.Persons.AsQueryable().Where(t => ageGroup.Contains(t.Age));
21 | QueryableAssert.AreEqual(a, b);
22 | }
23 |
24 | [TestMethod]
25 | public void NotIn()
26 | {
27 | IQueryable a, b;
28 | var ageGroup = new List() { 50, 58 };
29 | a = TestData.Persons.AsQueryable().Query(t => t.NotIn("Age", ageGroup));
30 | b = TestData.Persons.AsQueryable().Where(t => !ageGroup.Contains(t.Age));
31 | QueryableAssert.AreEqual(a, b);
32 | }
33 |
34 | [TestMethod]
35 | public void InString()
36 | {
37 | IQueryable a, b;
38 | var group = new List() { "David", "Michaela" };
39 | a = TestData.Persons.AsQueryable().Query(t => t.In("FirstName", group));
40 | b = TestData.Persons.AsQueryable().Where(t => group.Contains(t.FirstName));
41 | QueryableAssert.AreEqual(a, b);
42 | }
43 |
44 | [TestMethod]
45 | public void DiffTypeListConversion()
46 | {
47 | IQueryable a, b;
48 | var ageGroup = new List() { "28", "27", "50" };
49 | var ageGroupInt = ageGroup.Select(t => Convert.ToInt32(t)).ToList();
50 |
51 | a = TestData.Persons.AsQueryable().Query(t => t.In("Age", ageGroup));
52 | b = TestData.Persons.AsQueryable().Where(t => ageGroupInt.Contains(t.Age));
53 | QueryableAssert.AreEqual(a, b);
54 | }
55 |
56 | [TestMethod]
57 | public void MixingInWithCollectionPaths()
58 | {
59 | var titles = new List() { "Match" };
60 | var a = TestData.Authors.AsQueryable().Query(t => t.NullChecking(true).In("Posts.Title", titles));
61 | var b = TestData.Authors.AsQueryable().Where(t => t.Posts != null && t.Posts.Any(t2 => titles.Contains(t2.Title)));
62 | QueryableAssert.AreEqual(a, b);
63 | }
64 |
65 | [TestMethod]
66 | public void MixingInComplexPaths()
67 | {
68 | var authorsFirstNames = new List() { "David", "Pablo" };
69 | var a = TestData.Posts.AsQueryable().Query(t => t.In("Author.FirstName", authorsFirstNames));
70 | var b = TestData.Posts.AsQueryable().Where(t => authorsFirstNames.Contains(t.Author.FirstName));
71 | QueryableAssert.AreEqual(a, b);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Test/ConstantTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
5 | using PoweredSoft.DynamicLinq.Dal.Pocos;
6 |
7 | namespace PoweredSoft.DynamicLinq.Test
8 | {
9 | internal class ConstantTestClass
10 | {
11 | public int Id { get; set; }
12 | public int? ForeignKey { get; set; }
13 | public string Text { get; set; }
14 | }
15 |
16 | [TestClass]
17 | public class ConstantTests
18 | {
19 | internal List Posts { get; set; } = new List()
20 | {
21 | new ConstantTestClass { Id = 1, ForeignKey = null, Text = "Hello" },
22 | new ConstantTestClass { Id = 2, ForeignKey = 1, Text = "Hello 2" },
23 | new ConstantTestClass { Id = 3, ForeignKey = 2, Text = "Hello 3" },
24 | new ConstantTestClass { Id = 4, ForeignKey = null, Text = "Hello 4" },
25 | };
26 |
27 | [TestMethod]
28 | public void LeaveAsIs()
29 | {
30 | try
31 | {
32 | Posts
33 | .AsQueryable()
34 | .Query(t => t.Equal("ForeignKey", 1, QueryConvertStrategy.LeaveAsIs));
35 |
36 | Assert.Fail("Should have thrown an exception");
37 | }
38 | catch
39 | {
40 | }
41 |
42 | Assert.IsTrue(Posts.AsQueryable().Query(t => t.Equal("Id", 1, QueryConvertStrategy.LeaveAsIs)).Any());
43 | }
44 |
45 | [TestMethod]
46 | public void TestGuid()
47 | {
48 | var randomGuidStr = Guid.NewGuid().ToString();
49 | TestData.Uniques.AsQueryable().Query(t => t.Equal("RowNumber", randomGuidStr));
50 | TestData.Uniques.AsQueryable().Query(t => t.Equal("OtherNullableGuid", randomGuidStr));
51 | }
52 |
53 | [TestMethod]
54 | public void SpecifyType()
55 | {
56 | Assert.IsTrue(Posts.AsQueryable().Query(t => t.Equal("ForeignKey", 1, QueryConvertStrategy.SpecifyType)).Any());
57 | Assert.IsTrue(Posts.AsQueryable().Query(t => t.Equal("Id", 1, QueryConvertStrategy.SpecifyType)).Any());
58 |
59 | try
60 | {
61 | Posts.AsQueryable().Query(t => t.Equal("Id", "1", QueryConvertStrategy.SpecifyType));
62 | Assert.Fail("Should have thrown an exception");
63 | }
64 | catch
65 | {
66 |
67 | }
68 | }
69 |
70 | [TestMethod]
71 | public void ConvertConstantToComparedPropertyOrField()
72 | {
73 | Assert.IsTrue(Posts.AsQueryable().Query(t => t.Equal("ForeignKey", 1, QueryConvertStrategy.ConvertConstantToComparedPropertyOrField)).Any());
74 | Assert.IsTrue(Posts.AsQueryable().Query(t => t.Equal("ForeignKey", "1", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField)).Any());
75 | Assert.IsTrue(Posts.AsQueryable().Query(t => t.Equal("Id", 1, QueryConvertStrategy.ConvertConstantToComparedPropertyOrField)).Any());
76 | Assert.IsTrue(Posts.AsQueryable().Query(t => t.Equal("Id", "1", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField)).Any());
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Constants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace PoweredSoft.DynamicLinq
9 | {
10 | public enum ConditionOperators
11 | {
12 | Equal,
13 | NotEqual,
14 | GreaterThan,
15 | GreaterThanOrEqual,
16 | LessThan,
17 | LessThanOrEqual,
18 | Contains,
19 | NotContains,
20 | StartsWith,
21 | EndsWith,
22 | In,
23 | NotIn
24 | }
25 |
26 | public enum QueryConvertStrategy
27 | {
28 | LeaveAsIs,
29 | ConvertConstantToComparedPropertyOrField,
30 | SpecifyType
31 | }
32 |
33 | public enum QueryCollectionHandling
34 | {
35 | Any,
36 | All
37 | }
38 |
39 | public enum QueryOrderByDirection
40 | {
41 | Ascending,
42 | Descending
43 | }
44 |
45 | public enum SelectTypes
46 | {
47 | Key,
48 | Count,
49 | LongCount,
50 | Sum,
51 | Average,
52 | ToList,
53 | Path,
54 | Min,
55 | Max,
56 | LastOrDefault,
57 | FirstOrDefault,
58 | Last,
59 | First,
60 | }
61 |
62 | public enum SelectCollectionHandling
63 | {
64 | LeaveAsIs,
65 | Flatten
66 | }
67 |
68 | internal static class Constants
69 | {
70 | internal static readonly MethodInfo GroupByMethod = typeof(Queryable).GetMethods().First(t => t.Name == "GroupBy");
71 | internal static readonly MethodInfo GroupByMethodWithEqualityComparer = typeof(Queryable).GetMethods().First(t => t.Name == "GroupBy" && t.GetParameters().Any(t2 => t2.Name == "comparer"));
72 | internal static readonly MethodInfo StringEqualWithComparisation = typeof(string).GetMethod("Equals", new Type[] { typeof(string), typeof(StringComparison) });
73 | internal static readonly MethodInfo ContainsMethod = typeof(string).GetMethod("Contains", new Type[] { typeof(string) });
74 | internal static readonly MethodInfo StartsWithMethod = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) });
75 | internal static readonly MethodInfo StartsWithMethodWithComparisation = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string), typeof(StringComparison) });
76 | internal static readonly MethodInfo EndsWithMethod = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string) });
77 | internal static readonly MethodInfo EndsWithMethodWithComparisation = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string), typeof(StringComparison) });
78 | internal static readonly MethodInfo IndexOfMethod = typeof(string).GetMethod("IndexOf", new Type[] { typeof(string), typeof(StringComparison) });
79 | internal static readonly MethodInfo AnyMethod = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).First(t => t.Name == "Any" && t.GetParameters().Count() == 2);
80 | internal static readonly MethodInfo AllMethod = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).First(t => t.Name == "All" && t.GetParameters().Count() == 2);
81 | internal static readonly MethodInfo CompareToMethod = typeof(string).GetMethod("CompareTo", new Type[] { typeof(string) });
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Parser/ExpressionParser.cs:
--------------------------------------------------------------------------------
1 | using PoweredSoft.DynamicLinq.Helpers;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Linq.Expressions;
6 |
7 | namespace PoweredSoft.DynamicLinq.Parser
8 | {
9 | public class ExpressionParser
10 | {
11 | public ParameterExpression Parameter { get; protected set; }
12 | public string Path { get; set; }
13 | public List Pieces { get; set; } = new List();
14 | public bool IsParsed => Pieces?.Count > 0;
15 |
16 | public ExpressionParser(Type type, string path) : this(Expression.Parameter(type), path)
17 | {
18 |
19 | }
20 |
21 | public ExpressionParser(ParameterExpression parameter, string path)
22 | {
23 | Parameter = parameter;
24 | Path = path;
25 | }
26 |
27 | public static ExpressionParserPiece GetFirstEnumerableParent(ExpressionParserPiece piece)
28 | {
29 | if (piece.Parent == null)
30 | return null;
31 |
32 | if (piece.Parent.IsGenericEnumerable)
33 | return piece.Parent;
34 |
35 | return GetFirstEnumerableParent(piece.Parent);
36 | }
37 |
38 | public void Parse()
39 | {
40 | Pieces.Clear();
41 |
42 | var pathPieces = Path.Split('.').ToList();
43 | var param = Parameter;
44 | ExpressionParserPiece parent = null;
45 |
46 | pathPieces.ForEach(pp =>
47 | {
48 | var memberExpression = Expression.PropertyOrField(param, pp);
49 | var current = new ExpressionParserPiece
50 | {
51 | Type = memberExpression.Type,
52 | IsGenericEnumerable = QueryableHelpers.IsGenericEnumerable(memberExpression),
53 | EnumerableType = QueryableHelpers.GetTypeOfEnumerable(memberExpression.Type, false),
54 | Parent = parent,
55 | Name = pp
56 | };
57 |
58 | Pieces.Add(current);
59 |
60 | // for next iteration.
61 | param = Expression.Parameter(current.IsGenericEnumerable ? current.EnumerableType : current.Type);
62 | parent = current;
63 | });
64 | }
65 |
66 | private ExpressionParserPieceGroup CreateAndAddGroup(List groups, ParameterExpression parameter, ExpressionParserPieceGroup parent)
67 | {
68 | var group = new ExpressionParserPieceGroup();
69 | group.Parameter = parameter;
70 | group.Parent = parent;
71 | groups.Add(group);
72 | return group;
73 | }
74 |
75 | public List GroupBySharedParameters()
76 | {
77 | var groups = new List();
78 |
79 | var group = CreateAndAddGroup(groups, Parameter, null);
80 | Pieces.ForEach(piece =>
81 | {
82 | group.Pieces.Add(piece);
83 | if (piece.IsGenericEnumerable)
84 | group = CreateAndAddGroup(groups, Expression.Parameter(piece.EnumerableType), group);
85 | });
86 |
87 | // if the last piece is empty.
88 | if (group.Pieces.Count == 0)
89 | groups.Remove(group);
90 |
91 | return groups;
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29503.13
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.DynamicLinq", "PoweredSoft.DynamicLinq\PoweredSoft.DynamicLinq.csproj", "{5BB7E50F-8B40-4512-88DC-4B3BD89C9A5E}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.DynamicLinq.Test", "PoweredSoft.DynamicLinq.Test\PoweredSoft.DynamicLinq.Test.csproj", "{6F5C80F0-9045-4098-913F-7BDAD135E6DD}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.DynamicLinq.Dal", "PoweredSoft.DynamicLinq.Dal\PoweredSoft.DynamicLinq.Dal.csproj", "{C16927E7-1358-4B9D-BDD7-149E505DE6CC}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.DynamicLinq.EntityFramework", "PoweredSoft.DynamicLinq.EntityFramework\PoweredSoft.DynamicLinq.EntityFramework.csproj", "{82DADDB0-4A69-4E19-82AD-E73ABC8F1B4A}"
13 | EndProject
14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{77B4027B-ECB0-4ED1-8646-025AC4146CE2}"
15 | ProjectSection(SolutionItems) = preProject
16 | LICENSE = LICENSE
17 | README.md = README.md
18 | EndProjectSection
19 | EndProject
20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.DynamicLinq.EntityFrameworkCore", "PoweredSoft.DynamicLinq.EntityFrameworkCore\PoweredSoft.DynamicLinq.EntityFrameworkCore.csproj", "{BBF5805B-560C-474B-885B-9202281B42F7}"
21 | EndProject
22 | Global
23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
24 | Debug|Any CPU = Debug|Any CPU
25 | Release|Any CPU = Release|Any CPU
26 | EndGlobalSection
27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
28 | {5BB7E50F-8B40-4512-88DC-4B3BD89C9A5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {5BB7E50F-8B40-4512-88DC-4B3BD89C9A5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {5BB7E50F-8B40-4512-88DC-4B3BD89C9A5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {5BB7E50F-8B40-4512-88DC-4B3BD89C9A5E}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {6F5C80F0-9045-4098-913F-7BDAD135E6DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {6F5C80F0-9045-4098-913F-7BDAD135E6DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {6F5C80F0-9045-4098-913F-7BDAD135E6DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {6F5C80F0-9045-4098-913F-7BDAD135E6DD}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {C16927E7-1358-4B9D-BDD7-149E505DE6CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {C16927E7-1358-4B9D-BDD7-149E505DE6CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {C16927E7-1358-4B9D-BDD7-149E505DE6CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {C16927E7-1358-4B9D-BDD7-149E505DE6CC}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {82DADDB0-4A69-4E19-82AD-E73ABC8F1B4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {82DADDB0-4A69-4E19-82AD-E73ABC8F1B4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {82DADDB0-4A69-4E19-82AD-E73ABC8F1B4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {82DADDB0-4A69-4E19-82AD-E73ABC8F1B4A}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {BBF5805B-560C-474B-885B-9202281B42F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {BBF5805B-560C-474B-885B-9202281B42F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {BBF5805B-560C-474B-885B-9202281B42F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {BBF5805B-560C-474B-885B-9202281B42F7}.Release|Any CPU.Build.0 = Release|Any CPU
48 | EndGlobalSection
49 | GlobalSection(SolutionProperties) = preSolution
50 | HideSolutionNode = FALSE
51 | EndGlobalSection
52 | GlobalSection(ExtensibilityGlobals) = postSolution
53 | SolutionGuid = {EBCBC23C-D682-4818-A7AA-4142BF6989C2}
54 | EndGlobalSection
55 | EndGlobal
56 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Extensions/EnumerableExtensions.cs:
--------------------------------------------------------------------------------
1 | using PoweredSoft.DynamicLinq.Fluent;
2 | using System;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 |
8 | namespace PoweredSoft.DynamicLinq
9 | {
10 | public static class EnumerableExtensions
11 | {
12 | public static IEnumerable Where(this IEnumerable list, string path, ConditionOperators conditionOperator, object value,
13 | QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField,
14 | QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null)
15 | => list.AsQueryable().Where(path, conditionOperator, value, convertStrategy: convertStrategy, collectionHandling: collectionHandling, stringComparision: stringComparision);
16 |
17 | public static IEnumerable Where(this IEnumerable list, Action callback)
18 | => list.Query(callback);
19 |
20 | public static IEnumerable Query(this IEnumerable list, Action callback)
21 | => list.AsQueryable().Query(callback);
22 |
23 | public static IEnumerable Sort(this IEnumerable list, string path, QueryOrderByDirection sortDirection, bool appendSort)
24 | => list.AsQueryable().OrderBy(path, sortDirection, appendSort);
25 |
26 | public static IEnumerable OrderBy(this IEnumerable list, string path)
27 | => list.AsQueryable().OrderBy(path);
28 |
29 | public static IEnumerable OrderByDescending(this IEnumerable list, string path)
30 | => list.AsQueryable().OrderByDescending(path);
31 |
32 | public static IEnumerable ThenBy(this IEnumerable list, string path)
33 | => list.AsQueryable().ThenBy(path);
34 |
35 | public static IEnumerable ThenByDescending(this IEnumerable list, string path)
36 | => list.AsQueryable().ThenByDescending(path);
37 |
38 | public static IQueryable GroupBy(this IEnumerable list, string path)
39 | => list.AsQueryable().GroupBy(typeof(T), path);
40 |
41 | public static IQueryable GroupBy(this IEnumerable list, Type type, string path)
42 | => list.AsQueryable().GroupBy(type, path);
43 |
44 | public static IQueryable GroupBy(this IEnumerable list, Action callback)
45 | => list.AsQueryable().GroupBy(typeof(T), callback);
46 |
47 | public static IQueryable GroupBy(this IEnumerable list, Type type, Action callback)
48 | => list.AsQueryable().GroupBy(type, callback);
49 |
50 | public static IQueryable EmptyGroupBy(this IEnumerable list, Type underlyingType)
51 | => list.AsQueryable().EmptyGroupBy(underlyingType);
52 |
53 | public static List Reversed(this List list)
54 | {
55 | var copy = list.ToList();
56 | copy.Reverse();
57 | return copy;
58 | }
59 |
60 | public delegate void ForEachDelegate(T element, int index);
61 |
62 | public static void ForEach(this List list, ForEachDelegate callback)
63 | {
64 | for (var i = 0; i < list.Count; i++)
65 | callback(list[i], i);
66 | }
67 |
68 | public static void ReversedForEach(this List list, Action action)
69 | {
70 | list.Reversed().ForEach(action);
71 | }
72 |
73 | public static void ReversedForEach(this List list, ForEachDelegate callback)
74 | {
75 | for (var i = list.Count - 1; i >= 0; i--)
76 | callback(list[i], i);
77 | }
78 |
79 |
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Test/HelpersTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
5 | using PoweredSoft.DynamicLinq.Dal.Pocos;
6 | using PoweredSoft.DynamicLinq.Helpers;
7 |
8 | namespace PoweredSoft.DynamicLinq.Test
9 | {
10 | class Foo
11 | {
12 |
13 | }
14 |
15 | class ListOfFoo : List
16 | {
17 |
18 | }
19 |
20 | [TestClass]
21 | public class HelpersTests
22 | {
23 |
24 | [TestMethod]
25 | public void TestInheritanceOfListAsGenericEnumerableType()
26 | {
27 | var shouldBeTrue = QueryableHelpers.IsGenericEnumerable(typeof(ListOfFoo));
28 | Assert.IsTrue(shouldBeTrue);
29 | var type = QueryableHelpers.GetTypeOfEnumerable(typeof(ListOfFoo), true);
30 | Assert.IsTrue(type == typeof(Foo));
31 | }
32 |
33 | [TestMethod]
34 | public void TestCreateFilterExpression()
35 | {
36 | var authors = new List()
37 | {
38 | new Author
39 | {
40 | Id = 1,
41 | FirstName = "David",
42 | LastName = "Lebee",
43 | Posts = new List
44 | {
45 | new Post
46 | {
47 | Id = 1,
48 | AuthorId = 1,
49 | Title = "Match",
50 | Content = "ABC",
51 | Comments = new List()
52 | {
53 | new Comment()
54 | {
55 | Id = 1,
56 | DisplayName = "John Doe",
57 | CommentText = "!@#$!@#!@#",
58 | Email = "John.doe@me.com"
59 | }
60 | }
61 | },
62 | new Post
63 | {
64 | Id = 2,
65 | AuthorId = 1,
66 | Title = "Match",
67 | Content = "ABC",
68 | Comments = new List()
69 | }
70 | }
71 | },
72 | new Author
73 | {
74 | Id = 2,
75 | FirstName = "Chuck",
76 | LastName = "Norris",
77 | Posts = new List
78 | {
79 | new Post
80 | {
81 | Id = 3,
82 | AuthorId = 2,
83 | Title = "Match",
84 | Content = "ASD",
85 | Comments = new List()
86 | },
87 | new Post
88 | {
89 | Id = 4,
90 | AuthorId = 2,
91 | Title = "DontMatch",
92 | Content = "ASD",
93 | Comments = new List()
94 | }
95 | }
96 | }
97 | };
98 |
99 | // the query.
100 | var query = authors.AsQueryable();
101 |
102 | var allExpression = QueryableHelpers.CreateConditionExpression("Posts.Title", ConditionOperators.Equal, "Match", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.All);
103 | var anyExpression = QueryableHelpers.CreateConditionExpression("Posts.Title", ConditionOperators.Equal, "Match", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.Any);
104 | var anyExpression2 = QueryableHelpers.CreateConditionExpression("Posts.Comments.Email", ConditionOperators.Equal, "John.doe@me.com", QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, QueryCollectionHandling.Any);
105 | Assert.AreEqual(1, query.Count(allExpression));
106 | Assert.AreEqual(2, query.Count(anyExpression));
107 | Assert.AreEqual(1, query.Count(anyExpression2));
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Test/ComplexQueriesTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Data.SqlClient;
5 | using System.Linq;
6 | using System.Linq.Expressions;
7 | using System.Reflection;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using PoweredSoft.DynamicLinq;
11 | using PoweredSoft.DynamicLinq.Dal.Pocos;
12 | using PoweredSoft.DynamicLinq.Fluent;
13 |
14 | namespace PoweredSoft.DynamicLinq.Test
15 | {
16 | [TestClass]
17 | public class ComplexQueriesTests
18 | {
19 | [TestMethod]
20 | public void ComplexQueryBuilder()
21 | {
22 | // subject.
23 | var posts = new List()
24 | {
25 | new Post { Id = 1, AuthorId = 1, Title = "Hello 1", Content = "World" },
26 | new Post { Id = 2, AuthorId = 1, Title = "Hello 2", Content = "World" },
27 | new Post { Id = 3, AuthorId = 2, Title = "Hello 3", Content = "World" },
28 | };
29 |
30 | // the query.
31 | var query = posts.AsQueryable();
32 |
33 | query = query.Query(q =>
34 | {
35 | q.Compare("AuthorId", ConditionOperators.Equal, 1);
36 | q.And(sq =>
37 | {
38 | sq.Compare("Content", ConditionOperators.Equal, "World");
39 | sq.Or("Title", ConditionOperators.Contains, 3);
40 | });
41 | });
42 |
43 | Assert.AreEqual(2, query.Count());
44 | }
45 |
46 | [TestMethod]
47 | public void UsingQueryBuilder()
48 | {
49 | // subject.
50 | var posts = new List()
51 | {
52 | new Post { Id = 1, AuthorId = 1, Title = "Hello 1", Content = "World" },
53 | new Post { Id = 2, AuthorId = 1, Title = "Hello 2", Content = "World" },
54 | new Post { Id = 3, AuthorId = 2, Title = "Hello 3", Content = "World" },
55 | };
56 |
57 | // the query.
58 | var query = posts.AsQueryable();
59 | var queryBuilder = new WhereBuilder(query);
60 |
61 | queryBuilder.Compare("AuthorId", ConditionOperators.Equal, 1);
62 | queryBuilder.And(subQuery =>
63 | {
64 | subQuery.Compare("Content", ConditionOperators.Equal, "World");
65 | subQuery.Or("Title", ConditionOperators.Contains, 3);
66 | });
67 |
68 | query = (IQueryable)queryBuilder.Build();
69 | Assert.AreEqual(2, query.Count());
70 | }
71 |
72 | [TestMethod]
73 | public void TestingSort()
74 | {
75 | // subject.
76 | var posts = new List()
77 | {
78 | new Post { Id = 1, AuthorId = 1, Title = "Hello 1", Content = "World" },
79 | new Post { Id = 2, AuthorId = 1, Title = "Hello 2", Content = "World" },
80 | new Post { Id = 3, AuthorId = 2, Title = "Hello 3", Content = "World" },
81 | };
82 |
83 | // the query.
84 | var query = posts.AsQueryable();
85 | var queryBuilder = new OrderByBuilder(query);
86 |
87 | // add some sorting.
88 | queryBuilder
89 | .OrderByDescending("AuthorId")
90 | .ThenBy("Id");
91 |
92 | query = queryBuilder.Build().Cast();
93 |
94 | var first = query.First();
95 | var second = query.Skip(1).First();
96 |
97 | Assert.IsTrue(first.Id == 3);
98 | Assert.IsTrue(second.Id == 1);
99 | }
100 |
101 | [TestMethod]
102 | public void TestAutomaticNullChecking()
103 | {
104 | var authors = TestData.Authors;
105 |
106 | // the query.
107 | var query = authors.AsQueryable();
108 |
109 | query = query.Query(qb =>
110 | {
111 | qb.NullChecking();
112 | qb.And("Posts.Comments.Email", ConditionOperators.Equal, "john.doe@me.com", collectionHandling: QueryCollectionHandling.Any);
113 | });
114 |
115 | var query2 = query.Where(qb =>
116 | {
117 | qb.NullChecking();
118 | qb.And("Posts.Comments.Email", ConditionOperators.Equal, "john.doe@me.com", collectionHandling: QueryCollectionHandling.Any);
119 | });
120 |
121 | Assert.AreEqual(1, query.Count());
122 | Assert.AreEqual(1, query2.Count());
123 | }
124 |
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Helpers/TypeHelpers.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Reflection.Emit;
7 | using System.Reflection;
8 |
9 | namespace PoweredSoft.DynamicLinq.Helpers
10 | {
11 | public static class TypeHelpers
12 | {
13 | /*
14 | internal static Lazy DynamicAssemblyName = new Lazy(() => new AssemblyName("PoweredSoft.DynamicLinq.DynamicTypes"));
15 | internal static Lazy DynamicAssembly = new Lazy(() => AssemblyBuilder.DefineDynamicAssembly(DynamicAssemblyName.Value, AssemblyBuilderAccess.Run));
16 | internal static Lazy DynamicModule = new Lazy(() => DynamicAssembly.Value.DefineDynamicModule("PoweredSoft.DynamicLinq.DynamicTypes"));*/
17 |
18 | public static bool IsNullable(Type type)
19 | {
20 | if (!type.IsValueType)
21 | return true; // ref-type
22 |
23 | return Nullable.GetUnderlyingType(type) != null;
24 | }
25 |
26 |
27 |
28 |
29 | /*
30 | ///
31 | /// Use this to create anonymous type
32 | ///
33 | ///
34 | ///
35 | internal static TypeInfo CreateSimpleAnonymousType(List<(Type type, string name)> fields)
36 | {
37 | // DYNAMIC TYPE CREATION
38 | var typeName = $"PSDLProxy_{Guid.NewGuid().ToString("N")}";
39 | var dynamicType = DynamicModule.Value.DefineType(typeName, TypeAttributes.Class | TypeAttributes.Public);
40 | fields.ForEach(field =>
41 | {
42 | CreatePropertyOnType(dynamicType, field.name, field.type);
43 | });
44 | // not needed at the end.
45 | // CreateConstructorWithAllPropsOnType(dynamicType, fields);
46 | var ret = dynamicType.CreateTypeInfo();
47 | return ret;
48 | }*/
49 |
50 | /*
51 | * concstructor
52 | * https://stackoverflow.com/questions/6879279/using-typebuilder-to-create-a-pass-through-constructor-for-the-base-class
53 | * works but wasn't needed at the end.
54 | private static void CreateConstructorWithAllPropsOnType(TypeBuilder dynamicType, List<(Type type, string name)> fields)
55 | {
56 | var ctor = dynamicType.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, fields.Select(t => t.type).ToArray());
57 | var parameters = fields
58 | .Select((field, i) =>
59 | {
60 | return ctor.DefineParameter(i++, ParameterAttributes.None, $"{field.name}_1");
61 | })
62 | .ToList();
63 |
64 | var emitter = ctor.GetILGenerator();
65 | emitter.Emit(OpCodes.Nop);
66 |
67 | // Load `this` and call base constructor with arguments
68 | emitter.Emit(OpCodes.Ldarg_0);
69 | for (var i = 1; i <= parameters.Count; ++i)
70 | {
71 | emitter.Emit(OpCodes.Ldarg, i);
72 | }
73 | emitter.Emit(OpCodes.Call, ctor);
74 | emitter.Emit(OpCodes.Ret);
75 | }*/
76 |
77 | /*
78 | internal static void CreatePropertyOnType(TypeBuilder typeBuilder, string propertyName, Type propertyType)
79 | {
80 | // Generate a property called "Name"
81 | var field = typeBuilder.DefineField("_" + propertyName, propertyType, FieldAttributes.Private);
82 | var attributes = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
83 |
84 | // generate property
85 | var propertyBuilder = typeBuilder.DefineProperty(propertyName, PropertyAttributes.HasDefault, propertyType, null);
86 |
87 | // Generate getter method
88 | var getter = typeBuilder.DefineMethod("get_" + propertyName, attributes, propertyType, Type.EmptyTypes);
89 | var il = getter.GetILGenerator();
90 | il.Emit(OpCodes.Ldarg_0); // Push "this" on the stack
91 | il.Emit(OpCodes.Ldfld, field); // Load the field "_Name"
92 | il.Emit(OpCodes.Ret); // Return
93 | propertyBuilder.SetGetMethod(getter);
94 |
95 | // Generate setter method
96 | var setter = typeBuilder.DefineMethod("set_" + propertyName, attributes, null, new[] { propertyType });
97 | il = setter.GetILGenerator();
98 | il.Emit(OpCodes.Ldarg_0); // Push "this" on the stack
99 | il.Emit(OpCodes.Ldarg_1); // Push "value" on the stack
100 | il.Emit(OpCodes.Stfld, field); // Set the field "_Name" to "value"
101 | il.Emit(OpCodes.Ret); // Return
102 | propertyBuilder.SetSetMethod(setter);
103 | }
104 | */
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Fluent/Where/WhereBuilder.cs:
--------------------------------------------------------------------------------
1 | using PoweredSoft.DynamicLinq.Helpers;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Linq.Expressions;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace PoweredSoft.DynamicLinq.Fluent
10 | {
11 | public partial class WhereBuilder : IQueryBuilder
12 | {
13 | public IQueryable Query { get; set; }
14 | public Type QueryableType { get; set; }
15 | public List Filters { get; protected set; } = new List();
16 |
17 | public WhereBuilder(IQueryable query)
18 | {
19 | Query = query;
20 | QueryableType = query.ElementType;
21 | }
22 |
23 | public bool IsNullCheckingEnabled { get; protected set; } = false;
24 |
25 | public virtual WhereBuilder NullChecking(bool check = true)
26 | {
27 | IsNullCheckingEnabled = check;
28 | return this;
29 | }
30 |
31 | public virtual WhereBuilder Compare(string path, ConditionOperators conditionOperators, object value,
32 | QueryConvertStrategy convertStrategy = QueryConvertStrategy.ConvertConstantToComparedPropertyOrField,
33 | bool and = true, QueryCollectionHandling collectionHandling = QueryCollectionHandling.Any, StringComparison? stringComparision = null, bool negate = false)
34 | {
35 | Filters.Add(new WhereBuilderCondition
36 | {
37 | And = and,
38 | ConditionOperator = conditionOperators,
39 | Path = path,
40 | Value = value,
41 | ConvertStrategy = convertStrategy,
42 | CollectionHandling = collectionHandling,
43 | StringComparisation = stringComparision,
44 | Negate = negate
45 | });
46 |
47 | return this;
48 | }
49 |
50 | public virtual WhereBuilder SubQuery(Action subQuery, bool and = true)
51 | {
52 | // create query builder for same type.
53 | var qb = new WhereBuilder(Query);
54 | qb.NullChecking(IsNullCheckingEnabled);
55 |
56 | // callback.
57 | subQuery(qb);
58 |
59 | // create a query part.
60 | var part = new WhereBuilderCondition();
61 | part.And = and;
62 | part.Conditions = qb.Filters;
63 | Filters.Add(part);
64 |
65 | //return self.
66 | return this;
67 | }
68 |
69 | public virtual IQueryable Build()
70 | {
71 | // the query.
72 | var query = Query;
73 |
74 | if (Filters == null || Filters?.Count() == 0)
75 | return query;
76 |
77 | // shared parameter.
78 | var sharedParameter = Expression.Parameter(QueryableType, "t");
79 |
80 | // build the expression.
81 | var filterExpressionMerged = BuildConditionExpression(sharedParameter, Filters);
82 |
83 | // create the where expression.
84 | var whereExpression = Expression.Call(typeof(Queryable), "Where", new[] { query.ElementType }, query.Expression, filterExpressionMerged);
85 |
86 | // lets see what happens here.
87 | query = query.Provider.CreateQuery(whereExpression);
88 |
89 | return query;
90 | }
91 |
92 | protected virtual Expression BuildConditionExpression(ParameterExpression parameter, List filters)
93 | {
94 | Expression temp = null;
95 |
96 | filters.ForEach(filter =>
97 | {
98 | Expression innerExpression;
99 | if (filter.Conditions?.Any() == true)
100 | innerExpression = BuildConditionExpression(parameter, filter.Conditions);
101 | else
102 | innerExpression = BuildConditionExpression(parameter, filter);
103 |
104 | if (temp == null)
105 | {
106 | temp = innerExpression;
107 | }
108 | else
109 | {
110 | var body = ((LambdaExpression)temp).Body;
111 | var innerEpressionBody = ((LambdaExpression)innerExpression).Body;
112 |
113 | if (filter.And)
114 | temp = Expression.Lambda(Expression.AndAlso(body, innerEpressionBody), parameter);
115 | else
116 | temp = Expression.Lambda(Expression.OrElse(body, innerEpressionBody), parameter);
117 | }
118 |
119 | });
120 |
121 | return temp;
122 | }
123 |
124 | protected virtual Expression BuildConditionExpression(ParameterExpression parameter, WhereBuilderCondition filter)
125 | {
126 | var ret = QueryableHelpers.CreateConditionExpression(
127 | parameter.Type,
128 | filter.Path,
129 | filter.ConditionOperator,
130 | filter.Value,
131 | filter.ConvertStrategy,
132 | filter.CollectionHandling,
133 | parameter: parameter,
134 | nullChecking: IsNullCheckingEnabled,
135 | stringComparision: filter.StringComparisation,
136 | negate: filter.Negate
137 | );
138 |
139 | return ret;
140 | }
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq.Dal/Configurations/Configurations.cs:
--------------------------------------------------------------------------------
1 | using PoweredSoft.DynamicLinq.Dal.Pocos;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.ComponentModel.DataAnnotations.Schema;
5 | using System.Data.Entity.ModelConfiguration;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace PoweredSoft.DynamicLinq.Dal.Configurations
11 | {
12 | public class UniqueConfiguration : EntityTypeConfiguration
13 | {
14 | public UniqueConfiguration() : this("dbo")
15 | {
16 |
17 | }
18 |
19 | public UniqueConfiguration(string schema)
20 | {
21 | ToTable("Unique", schema);
22 | HasKey(t => t.Id);
23 | Property(t => t.Id).HasColumnName("Id").HasColumnType("bigint").IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
24 | Property(t => t.RowNumber).HasColumnType("uniqueidentifier").IsRequired();
25 | Property(t => t.OtherNullableGuid).HasColumnType("uniqueidentifier");
26 | }
27 | }
28 |
29 | public class AuthorConfiguration : EntityTypeConfiguration
30 | {
31 | public AuthorConfiguration() : this("dbo")
32 | {
33 |
34 | }
35 |
36 | public AuthorConfiguration(string schema)
37 | {
38 | ToTable("Author", schema);
39 | HasKey(t => t.Id);
40 | Property(t => t.Id).HasColumnName("Id").HasColumnType("bigint").IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
41 | Property(t => t.FirstName).HasColumnType("nvarchar").HasMaxLength(50).IsRequired();
42 | Property(t => t.LastName).HasColumnType("nvarchar").HasMaxLength(50).IsRequired();
43 |
44 | HasOptional(t => t.Website).WithMany(t => t.Authors).HasForeignKey(t => t.WebsiteId).WillCascadeOnDelete(false);
45 | }
46 | }
47 |
48 | public class PostConfiguration : EntityTypeConfiguration
49 | {
50 | public PostConfiguration() : this("dbo")
51 | {
52 |
53 | }
54 |
55 | public PostConfiguration(string schema)
56 | {
57 | ToTable("Post", schema);
58 | HasKey(t => t.Id);
59 | Property(t => t.Id).HasColumnName("Id").HasColumnType("bigint").IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
60 | Property(t => t.AuthorId).HasColumnName("AuthorId").HasColumnType("bigint").IsRequired();
61 | Property(t => t.Title).HasColumnName("Title").HasColumnType("nvarchar").HasMaxLength(100).IsRequired();
62 | Property(t => t.Content).HasColumnName("Content").HasColumnType("nvarchar(max)").IsRequired();
63 | Property(t => t.CreateTime).HasColumnName("CreateTime").HasColumnType("datetimeoffset").IsRequired();
64 | Property(t => t.PublishTime).HasColumnName("PublishTime").HasColumnType("datetimeoffset").IsOptional();
65 |
66 | HasRequired(t => t.Author).WithMany(t => t.Posts).HasForeignKey(t => t.AuthorId).WillCascadeOnDelete(false);
67 | }
68 | }
69 |
70 | public class CommentConfiguration : EntityTypeConfiguration
71 | {
72 | public CommentConfiguration() : this("dbo")
73 | {
74 |
75 | }
76 |
77 | public CommentConfiguration(string schema)
78 | {
79 | ToTable("Comment", schema);
80 | HasKey(t => t.Id);
81 | Property(t => t.Id).HasColumnName("Id").HasColumnType("bigint").IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
82 | Property(t => t.PostId).HasColumnName("PostId").HasColumnType("bigint").IsRequired();
83 | Property(t => t.DisplayName).HasColumnName("DisplayName").HasColumnType("nvarchar").HasMaxLength(100).IsRequired();
84 | Property(t => t.Email).HasColumnName("Email").HasColumnType("nvarchar").IsOptional();
85 | Property(t => t.CommentText).HasColumnName("CommentText").HasColumnType("nvarchar").HasMaxLength(255).IsOptional();
86 |
87 | HasRequired(t => t.Post).WithMany(t => t.Comments).HasForeignKey(t => t.PostId).WillCascadeOnDelete(false);
88 | }
89 | }
90 |
91 | public class CommentLikeConfiguration : EntityTypeConfiguration
92 | {
93 | public CommentLikeConfiguration() : this("dbo")
94 | {
95 | }
96 |
97 | public CommentLikeConfiguration(string schema)
98 | {
99 | ToTable("CommentLike", schema);
100 | HasKey(t => t.Id);
101 | Property(t => t.Id).HasColumnName("Id").HasColumnType("bigint").IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
102 | Property(t => t.CommentId).HasColumnName("CommentId").HasColumnType("bigint").IsRequired();
103 | Property(t => t.CreateTime).HasColumnName("CreateTime").HasColumnType("datetimeoffset").IsRequired();
104 |
105 | HasRequired(t => t.Comment).WithMany(t => t.CommentLikes).HasForeignKey(t => t.CommentId).WillCascadeOnDelete(false);
106 | }
107 | }
108 |
109 | public class WebsiteConfiguration : EntityTypeConfiguration
110 | {
111 | public WebsiteConfiguration() : this("dbo")
112 | {
113 |
114 | }
115 |
116 | public WebsiteConfiguration(string schema)
117 | {
118 | ToTable("Website", schema);
119 | HasKey(t => t.Id);
120 | Property(t => t.Id).HasColumnName("Id").HasColumnType("bigint").IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
121 | Property(t => t.Title).HasColumnName("Title").HasColumnType("nvarchar").HasMaxLength(100).IsRequired();
122 | Property(t => t.Url).HasColumnName("Url").HasColumnType("nvarchar").HasMaxLength(255).IsRequired();
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/Fluent/Select/SelectBuilder.cs:
--------------------------------------------------------------------------------
1 | using PoweredSoft.DynamicLinq.Helpers;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace PoweredSoft.DynamicLinq.Fluent
8 | {
9 | public class SelectPart
10 | {
11 | public string Path { get; set; }
12 | public string PropertyName { get; set; }
13 | public SelectTypes SelectType { get; set; }
14 | public SelectCollectionHandling SelectCollectionHandling { get; set; }
15 | }
16 |
17 | public class SelectBuilder : IQueryBuilder
18 | {
19 | public List Parts = new List();
20 | public Type DestinationType { get; set; }
21 | public bool Empty => Parts?.Count == 0;
22 | public IQueryable Query { get; protected set; }
23 | public bool IsNullCheckingEnabled { get; protected set; }
24 |
25 | public SelectBuilder(IQueryable query)
26 | {
27 | Query = query;
28 | }
29 |
30 | public SelectBuilder NullChecking(bool check = true)
31 | {
32 | IsNullCheckingEnabled = check;
33 | return this;
34 | }
35 |
36 | protected void ThrowIfUsedOrEmpty(string propertyName)
37 | {
38 | if (string.IsNullOrEmpty(propertyName))
39 | throw new ArgumentNullException($"{propertyName} cannot end up be empty.");
40 |
41 | if (Parts.Any(t => t.PropertyName == propertyName))
42 | throw new Exception($"{propertyName} is already used");
43 | }
44 |
45 | public SelectBuilder Aggregate(string path, SelectTypes type, string propertyName = null, SelectCollectionHandling selectCollectionHandling = SelectCollectionHandling.LeaveAsIs)
46 | {
47 | if (propertyName == null && path == null)
48 | throw new Exception("if property name is not specified, a path must be supplied.");
49 |
50 | if (propertyName == null)
51 | propertyName = path.Split('.').LastOrDefault();
52 |
53 | ThrowIfUsedOrEmpty(propertyName);
54 |
55 | Parts.Add(new SelectPart
56 | {
57 | Path = path,
58 | PropertyName = propertyName,
59 | SelectType = type,
60 | SelectCollectionHandling = selectCollectionHandling
61 | });
62 |
63 | return this;
64 | }
65 |
66 | public SelectBuilder Key(string propertyName, string path = null) => Aggregate(path == null ? "Key" : $"Key.{path}", SelectTypes.Key, propertyName);
67 | public SelectBuilder Path(string path, string propertyName = null) => Aggregate(path, SelectTypes.Path, propertyName);
68 | public SelectBuilder Count(string propertyName) => Aggregate(null, SelectTypes.Count, propertyName);
69 | public SelectBuilder LongCount(string propertyName) => Aggregate(null, SelectTypes.LongCount, propertyName);
70 | public SelectBuilder Sum(string path, string propertyName = null) => Aggregate(path, SelectTypes.Sum, propertyName);
71 | public SelectBuilder Average(string path, string propertyName = null) => Aggregate(path, SelectTypes.Average, propertyName);
72 | public SelectBuilder Min(string path, string propertyName = null) => Aggregate(path, SelectTypes.Min, propertyName);
73 | public SelectBuilder Max(string path, string propertyName = null) => Aggregate(path, SelectTypes.Max, propertyName);
74 | public SelectBuilder ToList(string propertyName) => Aggregate(null, SelectTypes.ToList, propertyName);
75 | public SelectBuilder LastOrDefault(string propertyName) => Aggregate(null, SelectTypes.LastOrDefault, propertyName);
76 | public SelectBuilder FirstOrDefault(string propertyName) => Aggregate(null, SelectTypes.FirstOrDefault, propertyName);
77 | public SelectBuilder Last(string propertyName) => Aggregate(null, SelectTypes.Last, propertyName);
78 | public SelectBuilder First(string propertyName) => Aggregate(null, SelectTypes.First, propertyName);
79 |
80 | [System.Obsolete("Use ToList instead", true)]
81 | public SelectBuilder PathToList(string path, string propertyName = null, SelectCollectionHandling selectCollectionHandling = SelectCollectionHandling.LeaveAsIs)
82 | => ToList(path, propertyName, selectCollectionHandling);
83 |
84 | public SelectBuilder ToList(string path, string propertyName = null, SelectCollectionHandling selectCollectionHandling = SelectCollectionHandling.LeaveAsIs)
85 | => Aggregate(path, SelectTypes.ToList, propertyName: propertyName, selectCollectionHandling: selectCollectionHandling);
86 |
87 | public SelectBuilder First(string path, string propertyName = null, SelectCollectionHandling selectCollectionHandling = SelectCollectionHandling.LeaveAsIs)
88 | => Aggregate(path, SelectTypes.First, propertyName: propertyName, selectCollectionHandling: selectCollectionHandling);
89 |
90 | public SelectBuilder FirstOrDefault(string path, string propertyName = null, SelectCollectionHandling selectCollectionHandling = SelectCollectionHandling.LeaveAsIs)
91 | => Aggregate(path, SelectTypes.FirstOrDefault, propertyName: propertyName, selectCollectionHandling: selectCollectionHandling);
92 |
93 | public SelectBuilder Last(string path, string propertyName = null, SelectCollectionHandling selectCollectionHandling = SelectCollectionHandling.LeaveAsIs)
94 | => Aggregate(path, SelectTypes.Last, propertyName: propertyName, selectCollectionHandling: selectCollectionHandling);
95 |
96 | public SelectBuilder LastOrDefault(string path, string propertyName = null, SelectCollectionHandling selectCollectionHandling = SelectCollectionHandling.LeaveAsIs)
97 | => Aggregate(path, SelectTypes.LastOrDefault, propertyName: propertyName, selectCollectionHandling: selectCollectionHandling);
98 |
99 | public virtual IQueryable Build()
100 | {
101 | if (Empty)
102 | throw new Exception("No select specified, please specify at least one select path");
103 |
104 | var partsTuple = Parts.Select(t => (selectType: t.SelectType, propertyName: t.PropertyName, path: t.Path, selectCollectionHandling: t.SelectCollectionHandling)).ToList();
105 | return QueryableHelpers.Select(Query, partsTuple, DestinationType, nullChecking: IsNullCheckingEnabled);
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/PoweredSoft.DynamicLinq/DynamicType/DynamicClass.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Dynamic;
3 | using System.Reflection;
4 |
5 | namespace PoweredSoft.DynamicLinq
6 | {
7 | ///
8 | /// https://github.com/StefH/System.Linq.Dynamic.Core/blob/master/src/System.Linq.Dynamic.Core/DynamicClass.cs
9 | ///
10 | public abstract class DynamicClass : DynamicObject
11 | {
12 | private Dictionary _propertiesDictionary;
13 |
14 | private Dictionary Properties
15 | {
16 | get
17 | {
18 | if (_propertiesDictionary == null)
19 | {
20 | _propertiesDictionary = new Dictionary();
21 |
22 | foreach (PropertyInfo pi in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
23 | {
24 | int parameters = pi.GetIndexParameters().Length;
25 | if (parameters > 0)
26 | {
27 | // The property is an indexer, skip this.
28 | continue;
29 | }
30 |
31 | _propertiesDictionary.Add(pi.Name, pi.GetValue(this, null));
32 | }
33 | }
34 |
35 | return _propertiesDictionary;
36 | }
37 | }
38 |
39 | ///
40 | /// Gets the dynamic property by name.
41 | ///
42 | /// The type.
43 | /// Name of the property.
44 | /// T
45 | public T GetDynamicPropertyValue(string propertyName)
46 | {
47 | var type = GetType();
48 | var propInfo = type.GetProperty(propertyName);
49 |
50 | return (T)propInfo.GetValue(this, null);
51 | }
52 |
53 | ///
54 | /// Gets the dynamic property value by name.
55 | ///
56 | /// Name of the property.
57 | /// value
58 | public object GetDynamicPropertyValue(string propertyName)
59 | {
60 | return GetDynamicPropertyValue