mirror of
				https://github.com/Biarity/Sieve.git
				synced 2025-11-04 02:39:00 +01:00 
			
		
		
		
	Merge branch 'master' into master
This commit is contained in:
		@@ -137,10 +137,12 @@ namespace Sieve.Services
 | 
				
			|||||||
                    if (property != null)
 | 
					                    if (property != null)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        var converter = TypeDescriptor.GetConverter(property.PropertyType);
 | 
					                        var converter = TypeDescriptor.GetConverter(property.PropertyType);
 | 
				
			||||||
                        dynamic filterValue = Expression.Constant(
 | 
					                        
 | 
				
			||||||
                            converter.CanConvertFrom(typeof(string))
 | 
					                        dynamic constantVal = converter.CanConvertFrom(typeof(string))
 | 
				
			||||||
                                ? converter.ConvertFrom(filterTerm.Value)
 | 
					                                                  ? converter.ConvertFrom(filterTerm.Value)
 | 
				
			||||||
                                : Convert.ChangeType(filterTerm.Value, property.PropertyType));
 | 
					                                                  : Convert.ChangeType(filterTerm.Value, property.PropertyType);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        Expression filterValue = GetClosureOverConstant(constantVal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        dynamic propertyValue = Expression.PropertyOrField(parameterExpression, property.Name);
 | 
					                        dynamic propertyValue = Expression.PropertyOrField(parameterExpression, property.Name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -217,6 +219,14 @@ namespace Sieve.Services
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Workaround to ensure that the filter value gets passed as a parameter in generated SQL from EF Core
 | 
				
			||||||
 | 
					        //See https://github.com/aspnet/EntityFrameworkCore/issues/3361
 | 
				
			||||||
 | 
					        private Expression GetClosureOverConstant<T>(T constant)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Expression<Func<T>> closure = () => constant;
 | 
				
			||||||
 | 
					            return closure.Body;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private IQueryable<TEntity> ApplySorting<TEntity>(
 | 
					        private IQueryable<TEntity> ApplySorting<TEntity>(
 | 
				
			||||||
            ISieveModel<IFilterTerm, ISortTerm> model,
 | 
					            ISieveModel<IFilterTerm, ISortTerm> model,
 | 
				
			||||||
            IQueryable<TEntity> result,
 | 
					            IQueryable<TEntity> result,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,5 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
 | 
					using System.ComponentModel.DataAnnotations.Schema;
 | 
				
			||||||
using Sieve.Attributes;
 | 
					using Sieve.Attributes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace SieveTests.Entities
 | 
					namespace SieveTests.Entities
 | 
				
			||||||
@@ -18,5 +19,9 @@ namespace SieveTests.Entities
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        [Sieve(CanFilter = true, CanSort = true)]
 | 
					        [Sieve(CanFilter = true, CanSort = true)]
 | 
				
			||||||
        public DateTimeOffset DateCreated { get; set; } = DateTimeOffset.UtcNow;
 | 
					        public DateTimeOffset DateCreated { get; set; } = DateTimeOffset.UtcNow;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Sieve(CanFilter = true, CanSort = true)]
 | 
				
			||||||
 | 
					        [Column(TypeName = "datetime")]
 | 
				
			||||||
 | 
					        public DateTime DateLastViewed { get; set; } = DateTime.UtcNow;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										47
									
								
								SieveTests/Migrations/20180522013323_AddDateLastViewedColumn.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								SieveTests/Migrations/20180522013323_AddDateLastViewedColumn.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
				
			|||||||
 | 
					// <auto-generated />
 | 
				
			||||||
 | 
					using Microsoft.EntityFrameworkCore;
 | 
				
			||||||
 | 
					using Microsoft.EntityFrameworkCore.Infrastructure;
 | 
				
			||||||
 | 
					using Microsoft.EntityFrameworkCore.Metadata;
 | 
				
			||||||
 | 
					using Microsoft.EntityFrameworkCore.Migrations;
 | 
				
			||||||
 | 
					using Microsoft.EntityFrameworkCore.Storage;
 | 
				
			||||||
 | 
					using Microsoft.EntityFrameworkCore.Storage.Internal;
 | 
				
			||||||
 | 
					using SieveTests.Entities;
 | 
				
			||||||
 | 
					using System;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace SieveTests.Migrations
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    [DbContext(typeof(ApplicationDbContext))]
 | 
				
			||||||
 | 
					    [Migration("20180522013323_AddDateLastViewedColumn")]
 | 
				
			||||||
 | 
					    partial class AddDateLastViewedColumn
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        protected override void BuildTargetModel(ModelBuilder modelBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					#pragma warning disable 612, 618
 | 
				
			||||||
 | 
					            modelBuilder
 | 
				
			||||||
 | 
					                .HasAnnotation("ProductVersion", "2.0.1-rtm-125")
 | 
				
			||||||
 | 
					                .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            modelBuilder.Entity("SieveTests.Entities.Post", b =>
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    b.Property<int>("Id")
 | 
				
			||||||
 | 
					                        .ValueGeneratedOnAdd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<int>("CommentCount");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<DateTimeOffset>("DateCreated");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<DateTime>("DateLastViewed")
 | 
				
			||||||
 | 
					                        .HasColumnType("datetime");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<int>("LikeCount");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<string>("Title");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.HasKey("Id");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.ToTable("Posts");
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					#pragma warning restore 612, 618
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					using Microsoft.EntityFrameworkCore.Migrations;
 | 
				
			||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace SieveTests.Migrations
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public partial class AddDateLastViewedColumn : Migration
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        protected override void Up(MigrationBuilder migrationBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            migrationBuilder.AddColumn<DateTime>(
 | 
				
			||||||
 | 
					                name: "DateLastViewed",
 | 
				
			||||||
 | 
					                table: "Posts",
 | 
				
			||||||
 | 
					                type: "datetime",
 | 
				
			||||||
 | 
					                nullable: false,
 | 
				
			||||||
 | 
					                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        protected override void Down(MigrationBuilder migrationBuilder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            migrationBuilder.DropColumn(
 | 
				
			||||||
 | 
					                name: "DateLastViewed",
 | 
				
			||||||
 | 
					                table: "Posts");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -29,6 +29,9 @@ namespace SieveTests.Migrations
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    b.Property<DateTimeOffset>("DateCreated");
 | 
					                    b.Property<DateTimeOffset>("DateCreated");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    b.Property<DateTime>("DateLastViewed")
 | 
				
			||||||
 | 
					                        .HasColumnType("datetime");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    b.Property<int>("LikeCount");
 | 
					                    b.Property<int>("LikeCount");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    b.Property<string>("Title");
 | 
					                    b.Property<string>("Title");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user