2013-05-07 1 views
3

포함 LINQ 식에서 2100 개가 넘는 요소를 사용하는 데 문제가 있으므로 포함 비교에 이전에 사용 된 값을 입력하기 위해 쿼리를 다시 작성하여 IEnumerable 형식의 구조체 EnquiryID 이에 대한 간단한 int 값 (ID)을 노출시키고 접합 :LLBLGen TypedConstantExpression을 SetExpression으로 변환 할 수 없습니다.

"입력 타입"System.Linq.Expressions.TypedConstantExpression '의 객체를 전송할 수 없음'SD :이 이러한 예외를 생성

IEnumerable<EnquiryID> enqIdList = ListToEnquiryIdList(enquiryIDs).ToList(); 

var extras = (from q in lmd.Quote 
join qe in lmd.QuoteExtra on q.Id equals qe.QuoteId 
join ei in enqIdList on q.EnquiryId equals ei.Id 
orderby qe.Created 
select new 
{ 
    EnquiryID = q.EnquiryId, qe.Created 
}).ToArray(); 

.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.SetExpression '. "명확하게 LLBLGEN 지정입니다. c

누구든지 아이디어가 있습니까?

+0

http://stackoverflow.com/questions/3132981/linq2sql-local-sequence-cannot-be-used-in-linq-to-sql-error 씨야 수 없습니다 로컬 시퀀스를 사용하십시오! –

+0

제 답변을 upvote 잊지 마세요! – Jay

+0

그게 더 힘들지는 않지만 ... 내 대답보기 – Jay

답변

1

당신은 너무처럼 TypedConstantExpression의 '가치'속성에 액세스 할 수 있습니다
(expression.Body을 MethodCallExpression로) .Object.GetType() GetProperty를 ("값") GetMethod.Invoke ((expression.Body을한다.. MethodCallExpression) .Object, 널 (null)) 표현이 LambdaExpression()=>(null).GetType()

에 의해 다음의 클래스와 테스트 완벽한 예를

static readonly Type TypedConstantExpressionType = Type.GetType("System.Linq.Expressions.TypedConstantExpression, System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); 

     static readonly PropertyInfo TypedConstantExpressionValueProperty; 

     [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized | System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] 
     static SymbolExtensions() 
     { 
      TypedConstantExpressionValueProperty = IntrospectionExtensions.GetTypeInfo(TypedConstantExpressionType).GetProperty("Value"); 
     } 

     /// <summary> 
     /// Given a lambda expression that expressed a new object, returns the <see cref="System.Reflection.TypeInfo"/> of what type was expected to be allocated 
     /// </summary> 
     /// <param name="expression"></param> 
     /// <returns></returns> 
     public static TypeInfo GetTypeInfo(Expression<Action> expression) //Expression<Action> allows the syntax() => where Expression would require a Delgate. 
     { 
      Expression body = expression.Body; 

      if (body is NewExpression) 
      { 
       NewExpression newExpression = expression.Body as NewExpression; 

       return IntrospectionExtensions.GetTypeInfo((expression.Body as NewExpression).Constructor.DeclaringType); 
      } 
      else if (body is MemberExpression) 
      { 
       MemberExpression memberExpression = body as MemberExpression; 

       return IntrospectionExtensions.GetTypeInfo(memberExpression.Member.DeclaringType); 
      } 
      else if (body is MethodCallExpression) 
      { 
       MethodCallExpression methodCallExpression = expression.Body as MethodCallExpression; 

       if (methodCallExpression.Object is MemberExpression) 
       { 
        return IntrospectionExtensions.GetTypeInfo((methodCallExpression.Object as MemberExpression).Member.DeclaringType); 
       } 

       //Actually a RuntimeType from a TypedConstantExpression... 
       return IntrospectionExtensions.GetTypeInfo((Type)TypedConstantExpressionValueProperty.GetMethod.Invoke(methodCallExpression.Object, null)); 
      } 

      throw new System.NotSupportedException("Please create an issue for your use case."); 
     } 

주어집니다

코드 :

public class MyTestClass 
     { 
      string m_Test; 

      public string Test 
      { 
       get { return m_Test; } 
       set { m_Test = value; } 
      } 
     } 

     public class MyTestClass<T> : MyTestClass 
     { 
      T Backing; 

      public T Property 
      { 
       [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] 
       get { return Backing; } 
       [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] 
       set { Backing = value; } 
      } 

      public T AnotherProperty 
      { 
       get; 
       set; 
      } 
     } 



System.Reflection.TypeInfo typeInfo = Media.Common.Extensions.ExpressionExtensions.SymbolExtensions.GetTypeInfo(() => new MyTestClass<int>()); 

      if (typeInfo.GetGenericArguments()[0] != typeof(int)) throw new System.Exception("Not correct type"); 

      System.Console.WriteLine("TypeInfo.Name" + typeInfo.Name); 

      System.Console.WriteLine("TypeInfo.MetadataToken" + typeInfo.MetadataToken); 

      if (typeInfo.GetGenericArguments()[0] != typeof(int)) throw new System.Exception("Not correct type"); 

      typeInfo = Media.Common.Extensions.ExpressionExtensions.SymbolExtensions.GetTypeInfo(() => (typeof(MyTestClass<int>)).GetType()); 

      if (typeInfo.GetGenericArguments()[0] != typeof(int)) throw new System.Exception("Not correct type"); 

      System.Type unboundedType = typeof(MyTestClass<>); 

      typeInfo = Media.Common.Extensions.ExpressionExtensions.SymbolExtensions.GetTypeInfo(() => (unboundedType).GetType()); 

      System.Console.WriteLine("TypeInfo.Name" + typeInfo.Name); 

      System.Console.WriteLine("TypeInfo.MetadataToken" + typeInfo.MetadataToken); 
+0

마찬가지로 ConstantExpression 클래스는 아마도 작동 할 것입니다.하지만 대부분의 경우 실제로 교환 할 수 있다고 생각되지만 TypedConstantExpression과 관련된 질문은 구체적으로 공개되지 않습니다. https://msdn.microsoft.com/en-us/library/system.linq.expressions.constantexpression(v=vs.110).aspx – Jay

+0

전체 예제 링크는 여기 (단위 테스트 포함)에서 찾을 수 있습니다. https://net7mma.codeplex.com/SourceControl/latest#Common/Extensions/SymbolExtensions.cs – Jay