2016-06-10 72 views
0

方法在視圖模型C#中的LINQ to EF返回null日期時SSMS顯示日期不爲空

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; } 
    } 

實體框架數據源是

<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 IS TBACACUNT

問題 所有日期返回null。

在SSMS(開發和PROD)

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

retuns

NtcDate = 2016年5月19日00:00:00 LastProtDate = 2016年6月20日00:00:00

回答

0

請確保您的SSMS和EF連接正在從相同的服務器/ db拉動,然後纔會失去主意:)

+1

發佈評論時未回答 – fahadash