我最近开始使用Visual Studio 2010。我已经升级了自2008年以来的解决方案。在此之后,我尝试运行我的项目,这是使用linq命令的非常简单的数据库搜索引擎,并且工作正常。然后我切换到.NET 4,从此我死在水中。任何linq查询都不会执行,也不会抛出任何异常。当我在执行linq命令时暂停时,它在DataContext.GetTable()方法上冻结。我所能想到的只是一些兼容性问题,但我无法弄清楚究竟是什么问题。升级到VS 2010和.NET 4.0后,LINQ停止工作
我的LINQ的命令是典型的“SELECT *”:
var query = from mateInfo in context.TableMateInfos
select mateInfo;
我使用SQL Server 2008中,我没有任何线索,为什么执行命令应停止工作后升级到.NET 4中,尤其是因为我仍然能够连接到数据库。当我在Management Studio中打开DB时,SQL命令(select * from TableMateInfo)工作得很好,并返回我想要的数据。有没有人有任何想法,哪里可能会被埋没的狗?
编辑:
我已经通过它的exe文件运行我的应用程序,以下异常已经抛出:
System.IO.FileLoadException: Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
at System.Signature.GetSignature(SignatureStruct& signature, Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Signature..ctor(IRuntimeFieldInfo fieldHandle, RuntimeType declaringType)
at System.Reflection.RtFieldInfo.get_FieldType()
at System.Data.Linq.SqlClient.TypeSystem.GetMemberType(MemberInfo mi)
at System.Data.Linq.Mapping.AttributedMetaDataMember..ctor(AttributedMetaType metaType, MemberInfo mi, Int32 ordinal)
at System.Data.Linq.Mapping.AttributedMetaType.InitDataMembers()
at System.Data.Linq.Mapping.AttributedMetaType..ctor(MetaModel model, MetaTable table, Type type, MetaType inheritanceRoot)
at System.Data.Linq.Mapping.AttributedRootType..ctor(AttributedMetaModel model, AttributedMetaTable table, Type type)
at System.Data.Linq.Mapping.AttributedMetaTable..ctor(AttributedMetaModel model, TableAttribute attr, Type rowType)
at System.Data.Linq.Mapping.AttributedMetaModel.GetTableNoLocks(Type rowType)
at System.Data.Linq.Mapping.AttributedMetaModel.GetTable(Type rowType)
at System.Data.Linq.DataContext.GetTable[TEntity]()
我已经加入app.config文件与以下内容完全相同exe文件和所有库所在的位置。我仍然有上面的错误。
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
你在用什么,LINQ2SQL,LINQ2Entites,LINQ2Fishticks?你可以用一个全新的项目重现它,将它连接到一个新的数据库,创建一个模型和一些查询,并检查是否发生了同样的事情。 – Arran
我正在使用LINQ2SQL。我会尝试新的项目,这可能是一个好主意 –
我认为你正面临'System.Data.Linq'命名空间类型error.plz检查你的页面是否有'System.Data.Linq'命名空间。 – Rahul