2013-05-20 231 views
1

我最近開始使用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> 
+1

你在用什麼,LINQ2SQL,LINQ2Entites,LINQ2Fishticks?你可以用一個全新的項目重現它,將它連接到一個新的數據庫,創建一個模型和一些查詢,並檢查是否發生了同樣的事情。 – Arran

+0

我正在使用LINQ2SQL。我會嘗試新的項目,這可能是一個好主意 –

+0

我認爲你正面臨'System.Data.Linq'命名空間類型error.plz檢查你的頁面是否有'System.Data.Linq'命名空間。 – Rahul

回答

0

問題是不同版本的.NET用來構建單個項目畢竟。如果沒有一個沒有useLegacyV2RuntimeActivationPolicy="true"屬性的話,上面的app.config文件就可以工作。我不得不手動添加它,現在它完美地工作。

0

我覺得你有Linq命名空間的問題,只要做一件事

Go to [project name] -> References -> Add reference -> System.Data.Linq 

通過Add references添加System.Data.Linq命名空間。

希望它可以解決您的問題

+0

不,它是我的參考 –

相關問題