how to change expression DateTime in EFCore

.net-core entity-framework-core

Question

i use EFCore to search DB.

When TValue == DateTime,it not run.

        /// <summary>
        /// 大于或等于
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        public void GreaterThanOrEqual<TValue>(string propertyName, TValue value)
        {
            var prop = type.GetProperty(propertyName);
            Expression left = Expression.Property(param, prop);
            Expression right = Expression.Constant(value, prop.PropertyType);
            Expression result = Expression.GreaterThanOrEqual(left, right);
            filter = Expression.And(filter, result);
        }

I see the cosole ,the sql is

 SELECT COUNT(*)
      FROM [tOrganization] AS [item]
      WHERE (1 & CASE
          WHEN [item].[CreateTime] >= '2013-02-26T00:00:00.0000000'
          THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT)
      END) = 1

but the column named CreateTime is datetime ,not datetime2.

how can i do ?

1
0
2/26/2019 8:33:02 AM

Popular Answer

the db entity property need to add [Column(TypeName = "datetime")] attribute. and the db entity property like money,decimal(18,15) ,need add this attribute too.

0
2/26/2019 1:42:03 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow