admin管理员组文章数量:1297045
I'm building an application, using .NET (8), EF Core (8) and Postgres (16). I use nodaTime for every date or time related task and NodaTime.Period
s are stored in pg as interval.
I configure them explicitly as interval via IEntityTypeConfiguration<MyType>
configurations.
Ef is configured like this:
services.AddDbContext<MyCtx>(opt => opt.UseNpgsql(conn, npgOpt => { npgOpt.UseNodaTime() }));
So far so good ... Now I want to fetch records, Where(e=>e.Period <= givenPeriod);
which gives a compiler error, as Periods cannot be compared directly. If I want to compare Periods in memory, I convert them to Duration (except they're to big) and compare Durations. That however could not be translated to valid sql.
Since this call is relatively simple at database level (SELECT * FROM "Entity" where "Period" > interval '8 hours'
) I wonder if there is a solution to query this with linq.
ctx.Entities.FromRawSql("SELECT * FROM ""Entities"" where ""Period"" > interval '8 hours'").ToListAsync();
Doesn't work either while the query returns expected results when executed directly - any ideas how to solve this preferably without raw sql?
One more thing... I found this github-comment where two different configurations regarding nodaTime for EF and npgsql are mentioned. Do I need to update my db-context configuration to solve this issue?
本文标签: cCompare NodaTimePeriods in EF CoreStack Overflow
版权声明:本文标题:c# - Compare NodaTime-Periods in EF Core - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741601355a2387719.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论