0

I use the Durandal template in my asp.net mvc solution. The question here is related to Breeze which is also used in Durandal. Let's say I have the following entity in my model:

public class Driver
{
    [Key]
    public int Id { get; set; }
    [Required]
    public string Firstname { get; set; }
    [Required]
    public string Lastname { get; set; }
    public string Comment { get; set; }
    public int? CreatedById { get; set; }
    public DateTime? CreatedTime { get; set; }
    public int? UpdatedById { get; set; }
    public DateTime? UpdatedTime { get; set; }

    public virtual User CreatedBy { get; set; }
    public virtual User UpdatedBy { get; set; }
}

As you can see, I have some properties used to track creation/updates for time and userid (UpdatedById, UpdatedTime, ...). I would like to let the user edit/create my drivers in some data entry pages then fill in these properties (UpdatedById, UpdatedTime, ...) server side automatically in the BeforeSaveEntity method.

It works but as you noted I had to allow nullable on the properties like int? or DateTime? because in case of adding a new entity (everything is blank) the validation failed if I didn't proceed like that.

My question: is there another solution or something that could be done to avoid using nullable types on my model (int? - DateTime?) for these properties which track my creation/edition?

Thanks.

4

1 回答 1

0

使它们不可为空并填写客户端的“虚拟”值,在每个类型的“注册”ctor中,然后将在服务器上被覆盖。

于 2013-07-16T17:33:26.407 回答