简体   繁体   English

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

[英]How to I create an extension in c# to return a new date time entry that can be converted in linq to entity?

So I have this property in a LinQ to entity query and I need to add days to it所以我在 LinQ to entity 查询中有这个属性,我需要添加天数

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)))),

The issue is I don't want to use "System.Data.Entity.DbFunctions.AddDays(a.DateTimeEntry, 90)" because I'm going to have to do this a lot and it's just so ugly to write that everytime... is it possible to make an extension where I can just call问题是我不想使用“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? 

Use a using statement.使用using语句。

using System.Data.Entity;
DBFunctions.AddDays(a.DateTimeEntry, 90) ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM