3

contains LINQ 式で 2100 を超える要素を使用すると問題が発生したため、contains 比較で以前に使用された値を EnquiryID 型の構造体の IEnumerable に挿入し、単純な int 値 (ID) を公開して結合するようにクエリを書き直しました。これ:

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();

これにより、次の例外が生成されます。

「タイプ 'System.Linq.Expressions.TypedConstantExpression' のオブジェクトをタイプ 'SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.SetExpression' にキャストできません。」、これは明らかに LLBLGEN 固有のものです

誰にもアイデアはありますか?

4

1 に答える 1

1

TypedConstantExpression次のような「Value」プロパティにアクセスできます:
(expression.Body as MethodCallExpression).Object.GetType().GetProperty("Value").GetMethod.Invoke((expression.Body as 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);
于 2016-06-08T03:23:02.427 に答える