2014-10-07 37 views
0

我有一個EmailHistoryModel:C#實體框架SQL錯誤

public class EmailHistory 
{ 
    public Guid Id { get; set; } 
    public string CompanyId { get; set; } 
    public Guid? UserId { get; set; } 
    public DateTime CreatedDate { get; set; } 
    public DateTime SentDate { get; set; } 
    public DateTime UpdateDate { get; set; } 
    public string OutCome { get; set; } 
    public DateTime EmailDeliveredDate { get; set; } 
    public DateTime EmailOpened { get; set; } 
    public string EmailAddress { get; set; } 
    public string HtmlEmail { get; set; } 
    public string IntegrationDocumentId { get; set; } 
    public Rules RulesId { get; set; } 
    public int TransactionId { get; set; } 
} 

試圖訪問我的模型時,我不斷收到一個錯誤。目前,我試圖運行以下命令:

var emailHistoryTotal = !emailHistory.Any() ? 1 : emailHistory.Count(); 

這一直給我的錯誤:「EntityFramework.dll但在用戶代碼中沒有處理

其他信息:從字符轉換時,轉換失敗字符串UNIQUEIDENTIFIER」

我不知道發生了什麼變化,因爲這是所有工作正常.....

如果我運行在SQL以下,則它返回OK!?SELECT * FROM [DBO ]。[EmailHistory] ​​

在SQL中,唯一設置爲唯一標識符的列是Id,RulesId_Id和UserId。

的emailHistory是從我正在添加庫(參見下面的方法)

public IQueryable<EmailHistory> GetEmailHistoryByUser(string userId) 
    {   
     return _autoSendContext.EmailHistory.AsQueryable(); 
    } 

的_autoSendContext是一個全局變量與DB

任何幫助或指導將是巨大的互動!

+0

'SELECT * FROM X'是不一樣的你的'! emailHistory.Any()...'你想要存檔的是什麼? – Marco 2014-10-07 13:15:03

+0

你究竟在哪裏填充模型? – markpsmith 2014-10-07 13:16:26

+0

'emailHistory'究竟是什麼? – juharr 2014-10-07 13:17:17

回答

0

好吧......這與電子郵件歷史記錄表無關。該錯誤是由於數據遷移導致的,自動遷移嘗試將數據庫中的字段從NVARCHAR更改爲唯一標識符。

這是該系統的聲明是試圖運行:ALTER TABLE [DBO] [交易] ALTER COLUMN [CompanyId] [唯一標識符] NULL