【问题标题】:Entity Framework 4 with SQL CE 4 Problem实体框架 4 与 SQL CE 4 问题
【发布时间】:2011-07-10 14:38:56
【问题描述】:

我通过创建模型创建了实体框架 4.0 应用程序。 SQL Server Compact 4.0 版数据库是使用this trick 创建的。

现在我完成了将初始数据导入数据库的所有代码(添加元素工作正常)。但是,如果我尝试通过

访问元素
 Context context = new Context();

 foreach (var c in context.Customers) // Exception
 {
     System.Diagnostics.Debug.Print(c.ToString());
 }

它在 foreach 循环开始时抛出异常:

[A]System.Data.SqlServerCe.SqlCeConnection cannot be cast to 
[B]System.Data.SqlServerCe.SqlCeConnection. Type A originates from 
'System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=89845dcd8080cc91' in the context 'Default' at location
'C:\Windows\assembly\GAC_MSIL\System.Data.SqlServerCe\4.0.0.0__89845dcd8080cc91\
System.Data.SqlServerCe.dll'. Type B originates from 'System.Data.SqlServerCe, 
Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' in the context
'Default' at location  'C:\Windows\assembly\GAC_MSIL\System.Data.SqlServerCe\
3.5.1.0__89845dcd8080cc91\System.Data.SqlServerCe.dll'.

我将这些引用添加到我的应用程序中:

System.Data.Entity - 4.0
System.Data.SqlServerCe - 4.0
System.Data.SqlServerCe.Entity - 4.0

有人知道,我的配置有什么问题吗?

PS:由于计算值,我想使用 SQL CE 4.0。如果我需要使用 3.5,我需要更改我的架构(或者是否可以在上下文类中实现计算值之类的东西?)。

【问题讨论】:

    标签: c# entity-framework sql-server-ce


    【解决方案1】:

    我认为您的 edmx 文件(在 XML 编辑器中查看)仍然引用 3.5,将其更改为 4.0

    【讨论】:

    • 你是对的。我之前更改了版本,但之后修改了一些内容。该版本已恢复到 3.5。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    相关资源
    最近更新 更多