2014-10-07 36 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