2013-06-02 88 views
0

代碼:實體框架:指定的方法不支持

List<MemberClass> Members = myEntity.users 
.Where(xXx => xXx.Status == m_Status && xXx.CompanyRef != m_CompanyRef 
    && xXx.userconfigs.FirstOrDefault().IsPublicProfile == true) 
.Select(xXx => new MemberClass { 
    Username = xXx.Username, 
    FullName = xXx.Name + " " + xXx.Surname, 
    Name = xXx.Name, 
    Surname = xXx.Surname, 
    AccessName = xXx.useraccess.Name, 
    RID = xXx.RID, 
    Email = xXx.Email }).ToList(); 

例外:

System.Data.EntityCommandCompilationException was unhandled by user code HResult=-2146232005 Message=An error occurred while preparing the command definition. See the inner exception for details. 
Source=System.Data.Entity StackTrace: 
at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) 
at System.Data.EntityClient.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) 
at System.Data.EntityClient.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) 
at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree) 
at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection1 compiledQueryParameters, AliasGenerator aliasGenerator) 
at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable1 forMergeOption) 
at System.Data.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) 
at System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() 
at System.Collections.Generic.List1..ctor(IEnumerable1 collection) 
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) 
at MemberHelper.MemberHelperDB.getExternalMemberList(Decimal m_CompanyRef, Decimal m_Status) in c:\Users\Dreamcatcher\Documents\Visual Studio 2010\SVN Projects\OZTranV4\OZTranV4\App_Code\Helper\MemberHelperDB.cs:line 54 
at popup_AddMemberToWork2.gridExternalUser_NeedDataSource(Object sender, GridNeedDataSourceEventArgs e) in c:\Users\Dreamcatcher\Documents\Visual Studio 2010\SVN Projects\OZTranV4\OZTranV4\popup\AddMemberToWork2.aspx.cs:line 157 
at Telerik.Web.UI.RadGrid.OnNeedDataSource(GridNeedDataSourceEventArgs e) 
at Telerik.Web.UI.RadGrid.ObtainDataSource(GridRebindReason rebindReason, Boolean IsBoundUsingDataSourceId) 
at Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) 
at Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
InnerException: System.NotSupportedException HResult=-2146233067 Message=Specified method is not supported. Source=MySql.Data.Entity StackTrace: 
at MySql.Data.Entity.SqlGenerator.Visit(DbApplyExpression expression) 
at System.Data.Common.CommandTrees.DbApplyExpression.Accept[TResultType](DbExpressionVisitor1 visitor) 
at MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type) 
at MySql.Data.Entity.SelectGenerator.HandleJoinExpression(DbExpressionBinding left, DbExpressionBinding right, DbExpressionKind joinType, DbExpression joinCondition) 
at MySql.Data.Entity.SelectGenerator.Visit(DbJoinExpression expression) 
at System.Data.Common.CommandTrees.DbJoinExpression.Accept[TResultType](DbExpressionVisitor1 visitor) 
at MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type) 
at MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type) 
at MySql.Data.Entity.SelectGenerator.Visit(DbFilterExpression expression) 
at System.Data.Common.CommandTrees.DbFilterExpression.Accept[TResultType](DbExpressionVisitor1 visitor) 
at MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type) 
at MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type) 
at MySql.Data.Entity.SelectGenerator.Visit(DbProjectExpression expression) 
at System.Data.Common.CommandTrees.DbProjectExpression.Accept[TResultType](DbExpressionVisitor1 visitor) 
at MySql.Data.Entity.SelectGenerator.GenerateSQL(DbCommandTree tree) 
at MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) 
at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree) 
at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) 

此代碼正在格式化我的電腦前。我使用MySQL 5.5.12,MySQL .NET連接器版本6.5.4。只有Netframework版本可能會發生變化,我已經完成了所有的Windows更新,當安裝Visual Studio 2012時,會自動安裝.Net 4.5。

我該如何解決這個問題?

+0

可能重複的:http://stackoverflow.com/questions/14157877/net-framework-4-5-using-entity-framework-and-my – haim770

+0

安裝後異常是,有問題ms看起來很像,但不幸的是沒有解決方案。 – Dreamcatcher

+0

「m_Status」和「m_CompanyRef」的類型是什麼? –

回答

0

而不是使用

xXx.userconfigs.FirstOrDefault().IsPublicProfile == true; 

trylike如下─

xXx.userconfigs.Select(s=>s.IsPublicProfile).FirstOrDefault()==true; 

然後整個代碼看起來像如下─

List<MemberClass> Members = myEntity.users 
    .Where(xXx => xXx.Status == m_Status && xXx.CompanyRef != m_CompanyRef 
    && xXx.userconfigs.Select(s=>s.IsPublicProfile).FirstOrDefault()==true) 
    .Select(xXx => new MemberClass { 
     Username = xXx.Username, 
     FullName = xXx.Name + " " + xXx.Surname, 
     Name = xXx.Name, 
     Surname = xXx.Surname, 
     AccessName = xXx.useraccess.Name, 
     RID = xXx.RID, 
     Email = xXx.Email }).ToList();