当SSMS显示date不为null时,c#linq to EF返回null日期

时间:2016-06-10 17:08:46

标签: c#

VIEWMODEL中的方法

public List<AccountStatusData> GetAccounts()
        //public List<tblAccount> GetAccounts()
        {
            var query = (from a in this._db.tblAccounts
                         select new AccountStatusData
                         {
                             AcctID = a.AcctID,
                             PropID = a.PropID,
                             AcctLegal = a.AcctLegal,
                             Cad = a.Cad,                             
                             NtcDate = a.NtcDate,                             
                             LastProtDate = a.LastProtDate,
                             CrtDate = a.CrtDate,
                             //NtcDate = a.NtcDate.ToString(),
                             //LastProtDate = a.LastProtDate.ToString(),
                             //CrtDate = a.CrtDate.ToString(),
                             CrtStat = a.CrtStat,
                             ProtStat = a.ProtStat,
                             Stat_YN = a.Stat_YN
                         });
            //var query = (from a in this._db.tblAccounts select a);
            //query = query.Where(x => x.Cad == this.ReportCad);
            query = query.Where(x => x.Cad == "BAN");
            query = query.Where(x => x.Stat_YN == true);
            //query = query.Where(x => x.AcctID == 396329);
            query = query.Where(x => x.NtcDate != null);
            return query.ToList();
        }

模特中的类型

 public class AccountStatusData
    {
        public int AcctID { get; set; }
        public int? PropID { get; set; }
        public string AcctLegal { get; set; }
        public string Cad { get; set; }

        //public string NtcDate { get; set; }
        //public string LastProtDate { get; set; }
        //public string CrtDate { get; set; }

        public DateTime? NtcDate { get; set; }
        public DateTime? LastProtDate { get; set; }
        public DateTime? CrtDate { get; set; }
        public short? CrtStat { get; set; }
        public short? ProtStat { get; set; }
        public bool Stat_YN { get; set; }
    }

ENTITY FRAMEWORK DATA SOURCE

<connectionStrings>
    <add name="WagDataEntities" connectionString="metadata=
         res://*/Services.Model1.csdl|res://*/Services.Model1.ssdl|
         res://*/Services.Model1.msl;provider=System.Data.SqlClient;
         provider connection string=&quot;data source=FILESERVER02\DEV;
         initial catalog=WagData;
         integrated security=True;
         MultipleActiveResultSets=True;
         App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>                   
  </connectionStrings>

SOURCE TABLE是TBLACCOUNT

问题 所有日期都返回null。

SSMS(Dev and Prod)中的

select AcctID , NtcDate,LastProtDate
  FROM [WagData].[dbo].[tblAccount]
  where AcctID=396329

retuns

NtcDate = 2016-05-19 00:00:00 LastProtDate = 2016-06-20 00:00:00

1 个答案:

答案 0 :(得分:0)

在失去理智之前,请确保您的SSMS和EF连接从同一服务器/ db中拉出来:)