我有一个框架,在数据库中实现软删除(Nullable DateTime称为DeletedDate).我正在使用Repository来处理主要实体请求,如下所示:
/// <summary>
/// Returns a Linq Queryable instance of the entity collection.
/// </summary>
public IQueryable<T> All
{
get { return Context.Set<T>().Where(e => e.DeletedDate == null); }
}
Run Code Online (Sandbox Code Playgroud)
这很好用,但我遇到的问题是当你包含导航属性时,以及如何确保只查询活动记录.有问题的存储库方法如下所示:
/// <summary>
/// Returns a Linq Queryable instance of the entity collection, allowing connected objects to be loaded.
/// </summary>
/// <param name="includeProperties">Connected objects to be included in the result set.</param>
/// <returns>An IQueryable collection of entity.</returns>
public IQueryable<T> AllIncluding(params Expression<Func<T, object>>[] includeProperties)
{
IQueryable<T> query = Context.Set<T>().Where(e => …Run Code Online (Sandbox Code Playgroud) 我正在构建“调度屏幕”,需要显示一个“时间”字段,以便用户输入调度的一天中的时间。
我不确定这是否是最佳选择,但我在该字段中使用了TimeSpan。为了验证输入,我想使用Range属性和DisplayFormat属性。
当我调试并输入看似有效的值时,Range属性指示超出范围的错误。谁能看到我在做什么错?TimeSpan是否适合此用法?任何帮助是极大的赞赏。
型号类别:
public class Schedule
{
public Schedule()
{
this.ScheduleTime = new TimeSpan(0, 0, 0);
}
/// <summary>
/// The time of day for the schedule to run
/// </summary>
[Required, DataType(System.ComponentModel.DataAnnotations.DataType.Time),
Display(Name = "Schedule Time", Description = "Number of Hours and Minutes after Midnight Central Timezone"),
DisplayFormat(DataFormatString = @"{0:hh\:mm\:ss}", ApplyFormatInEditMode = true),
Range(typeof(TimeSpan), "00:00", "23:59")]
public TimeSpan ScheduleTime { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
错误信息:

我有一个文本字段属性,我不希望用户能够输入正斜杠或反斜杠.是否有数据属性或我是否需要使用该RegularExpression属性?
这似乎很常见,但我没有找到答案的运气.我不熟悉正则表达式,所以我现在正在研究它们.