我如何在c#中创建扩展名以返回可以在linq中转换为实体的新日期时间条目?

问题描述 投票:1回答:1

因此,我在LinQ中具有此属性以进行实体查询,并且需要向其中添加天数

isWithinNinetyDays = (a.ParcelData == null ? false :
    (a.ParcelData.Parcel_LetterTracking == null ? false : 
        (a.ParcelData.Parcel_LetterTracking.LMailDate == null ? false : 
            (System.Data.Entity.DbFunctions.AddDays(a.DateTimeEntry, 90) >= a.ParcelData.Parcel_LetterTracking.LMailDate.Value)))),

问题是我不想使用“ System.Data.Entity.DbFunctions.AddDays(a.DateTimeEntry,90)”,因为我将不得不做很多事情,并且编写它是如此丑陋每次...有可能做一个我可以打电话给的分机

a.DateTimeEntry.MyExtension(90)
that will add 90 days and be able to convert it to a entity convertable to sql object? 
c# entity-framework extension-methods
1个回答
1
投票

使用using别名。

using DB = System.Data.Entity.DbFunctions;
DB.AddDays(a.DateTimeEntry, 90) ...
© www.soinside.com 2019 - 2024. All rights reserved.