0

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 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.