合同不会返回null数据成员

时间:2016-06-13 07:15:29

标签: c# wcf datacontract

我是使用C#的WCF新手。 我从数据库获取数据集合,我有与我的服务相关的合同,但我的服务不会从合同中返回null属性。

任何帮助都将受到高度赞赏。

这是我的合同。

[DataContract(Name = "TaskCustomId", Namespace = "")]
[KnownType(typeof(PMT.Service.Contract.TaskCustomId))]
[KnownType(typeof(List<PMT.Service.Contract.TaskCustomId>))]
[KnownType(typeof(List<Object>))]
[KnownType(typeof(Object))]
[KnownType(typeof(List<PMT.Base.Model.TaskCombinedObject>))]
[KnownType(typeof(PMT.Base.Model.TaskCombinedObject))]
[KnownType(typeof(List<ProjectCustomId>))]
[KnownType(typeof(PMT.Base.Helper.Pagination))]
[KnownType(typeof(List<PMT.Base.Helper.Pagination>))]
[KnownType(typeof(List<PMT.Base.Model.Milestone>))]
[KnownType(typeof(List<PMT.Base.Model.Progress>))]
[KnownType(typeof(List<PMT.Base.Model.Timeline>))]
[KnownType(typeof(List<PMT.Base.Model.User>))]
[KnownType(typeof(PMT.Base.Model.User))]
[KnownType(typeof(PMT.Base.Model.Resource))]
[KnownType(typeof(PMT.Base.Model.ProjectValues))]
[KnownType(typeof(PMT.Base.Model.ProjectClient))]
[KnownType(typeof(PMT.Base.Model.PriorityWrapper))]
[KnownType(typeof(User))]
[KnownType(typeof(List<PMT.Base.Model.Group>))]

public class TaskCustomId : Pagination
{
    public TaskCustomId()
    {

    }


    public TaskCustomId(PMT.Base.Model.TaskCombinedObject Model)
    {
        Id = Model.Id;
        Name = Model.Name;
        CreatorId = Model.CreatorId;
        if (Model.Description != null)
            Notes = Model.Description;

        if (Model.Priority != 0)
            Priority = Model.Priority;

        if (Model.Stage != 0)
            Stage = Model.Stage;

        if (Model.Status != 0)
            NoticeStatus = Convert.ToString(Model.Status);

        leaf = true;
        Object = 0;

        if (Model.StartDate != null)
            StartDate = Model.StartDate;
        else
            StartDate = null;

        if (Model.EndDate != null)
            EndDate = Model.EndDate;
        else
            EndDate = null;

        if (Model.EndDate != null)
            LateFinish = Model.LateFinish;
        else
            LateFinish = null;

        if (Model.LateStart != null)
            LateStart = Model.LateStart;
        else
            LateStart = null;

        if (Model.EarlyStart != null)
            EarlyStart = Model.EarlyStart;
        else
            EarlyStart = null;

        isCriticalTask = new Random().Next(100) % 2 == 0;
        isClarificationRequired = new Random().Next(100) % 2 == 0; ;
        isNotice = new Random().Next(100) % 2 == 0;
        isReshow = new Random().Next(100) % 2 == 0;
        isCompleted = new Random().Next(100) % 2 == 0;
        isPassive = new Random().Next(100) % 2 == 0;
        isCancelled = new Random().Next(100) % 2 == 0;

        if (Model.ActualStart != null)
            Actual_Start = Model.ActualStart;
        else
            Actual_Start = null;

        if (Model.ActualEnd != null)
            Actual_Finish = Model.ActualEnd;
        else
            Actual_Finish = null;

        if (Model.RemTime != null)
            Rem_Time = Model.RemTime;
        else
            Rem_Time = null;

        if (Model.Completed != null)
            Completed = Model.Completed;
        else
            Completed = null;

        if (Model.ActualDuration != 0)
            Actual_Duration = Model.ActualDuration;
        else
            Actual_Duration = 0;
            //float.Parse(Convert.ToString(Model.GetType().GetProperty("ActualDuration").GetValue(Model, null)), System.Globalization.CultureInfo.InvariantCulture);
        if (Model.ActualDuration != 0)
            Duration_Act_Pld = Model.ActualDuration; 
        else
            Duration_Act_Pld = 0;
            //float.Parse(Convert.ToString(Model.GetType().GetProperty("ActualDurationPlanned").GetValue(Model, null)), System.Globalization.CultureInfo.InvariantCulture); */
    }

    internal List<TaskCustomId> GetTaskList(List<PMT.Base.Model.TaskCombinedObject> TaskListView)
    {
        List<TaskCustomId> TasksList = new List<TaskCustomId>();
        foreach (PMT.Base.Model.TaskCombinedObject MTask in TaskListView)
        {
            TasksList.Add(new TaskCustomId(MTask));
        }
        return TasksList;
    }

    public TaskCustomId ToModel(PMT.Base.Model.TaskCombinedObject Model)
    {
        return null;
    }

    [DataMember(IsRequired = true)]
    public String Id { get; set; }

    [DataMember(IsRequired = true)]
    public String Name { get; set; }

    [DataMember(IsRequired = true)]
    public int CreatorId { get; set; }

    [DataMember(IsRequired = true)]
    public string Notes = null;

    [DataMember(IsRequired = true)]
    public int Priority = 0;

    [DataMember(IsRequired = true)]
    public int Stage = 0;

    [DataMember(IsRequired = true)]
    public string NoticeStatus = null;

    [DataMember(IsRequired = true)]
    public bool leaf = false;

    [DataMember(IsRequired = true)]
    public int Object = 0;

    [DataMember(IsRequired = true)]
    public Nullable<DateTime> StartDate = null;

    [DataMember(IsRequired = true)]
    public Nullable<DateTime> EndDate = null;

    [DataMember(IsRequired = true)]
    public Nullable<DateTime> LateFinish = null;

    [DataMember(IsRequired = true)]
    public Nullable<DateTime> LateStart = null;

    [DataMember(IsRequired = true)]
    public Nullable<DateTime> EarlyStart = null;

    [DataMember(IsRequired = true)]
    public bool isCriticalTask = false;

    [DataMember(IsRequired = true)]
    public bool isClarificationRequired = false;

    [DataMember(IsRequired = true)]
    public bool isNotice = false;

    [DataMember(IsRequired = true)]
    public bool isReshow = false;

    [DataMember(IsRequired = true)]
    public bool isCompleted = false;

    [DataMember(IsRequired = true)]
    public bool isPassive = false;

    [DataMember(IsRequired = true)]
    public bool isCancelled = false;

    [DataMember(IsRequired = true)]
    public int ParentId = 0;

    [DataMember(IsRequired = true)]
    public Nullable<DateTime> Actual_Start = null;

    [DataMember(IsRequired = true)]
    public Nullable<DateTime> Actual_Finish = null;

    [DataMember(IsRequired = true)]
    public string Rem_Time = null;

    [DataMember(IsRequired = true)]
    public Nullable<DateTime> Completed = null;

    [DataMember(IsRequired = true)]
    public float Actual_Duration = 0;

    [DataMember(IsRequired = true)]
    public float Duration_Act_Pld = 0;
}

0 个答案:

没有答案