[英]Entity Framework - Precision in queries
Very similar to this question: Why is Entity Framework passing a parameter as DECIMAL(5,0) for a column defined with NUMERIC(19)? 与此问题非常相似: 为什么实体框架将参数作为DECIMAL(5,0)传递给使用NUMERIC(19)定义的列?
However, the answer given doesn't seem to align with my results. 但是,给出的答案似乎与我的结果不一致。
I have a column, OrderEntryTimeUtc datetime2(0)
over which the table is partitioned. 我有一个
OrderEntryTimeUtc datetime2(0)
列,表被分区。 Now, in order to actually use the partitioning, I need my queries to use the same type and precision. 现在,为了实际使用分区,我需要我的查询使用相同的类型和精度。
But when I create my where clause: 但是当我创建我的where子句时:
o.OrderEntryTimeUtc > dateStart
where dateStart is a DateTime with the ms part set to 0, I get the following generated parameter: 其中dateStart是一个DateTime,ms部分设置为0,我得到以下生成的参数:
@p__linq__2 datetime2(7)
@p__linq__2='2016-05-21 23:44:33'
How can I force EF to send a datetime2(0)
? 如何强制EF发送
datetime2(0)
? Or how can I add a CONVERT
to my query without having to write the whole query in SQL or create a view? 或者如何在我的查询中添加
CONVERT
而无需在SQL中编写整个查询或创建视图?
You can use the modelBuilder 您可以使用modelBuilder
modelBuilder.Entity<YourEntity>()
.Property(p => p.OrderEntryTimeUtc)
.HasColumnType("datetime2")
.HasPrecision(0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.