MemberAccessIsAccessingDbContext() public static method

public static MemberAccessIsAccessingDbContext ( MemberAccessExpressionSyntax memberExpr, SyntaxNodeAnalysisContext context, EFUsageContext efContext, EFCodeFirstClassInfo &clsInfo ) : bool
memberExpr MemberAccessExpressionSyntax
context SyntaxNodeAnalysisContext
efContext EFUsageContext
clsInfo EFCodeFirstClassInfo
return bool
コード例 #1
0
        static bool GetRootEntityTypeFromLinqQuery(ExpressionSyntax expr, SyntaxNodeAnalysisContext context, EFUsageContext efContext, out EFCodeFirstClassInfo clsInfo)
        {
            clsInfo = null;

            // from $var in ???
            var memberExpr = expr as MemberAccessExpressionSyntax;
            var ident      = expr as IdentifierNameSyntax;

            if (memberExpr != null) //??? = $ident.$prop
            {
                return(LinqExpressionValidator.MemberAccessIsAccessingDbContext(memberExpr, context, efContext, out clsInfo));
            }
            else if (ident != null)
            {
                var si    = context.SemanticModel.GetSymbolInfo(ident);
                var local = si.Symbol as ILocalSymbol;
                if (local != null)
                {
                    var nts = local.Type as INamedTypeSymbol;
                    if (nts != null && nts.TypeArguments.Length == 1)
                    {
                        var typeArg = nts.TypeArguments[0];
                        clsInfo = efContext.GetClassInfo(typeArg);
                        if (clsInfo != null)
                        {
                            return(LinqExpressionValidator.SymbolCanBeTracedBackToDbContext(local, context, efContext, clsInfo));
                        }
                    }
                }
            }
            return(false);
        }
コード例 #2
0
        public static Dictionary <string, ContextualLinqParameter> BuildContext(QueryExpressionSyntax query, SyntaxNodeAnalysisContext context, EFUsageContext efContext)
        {
            var cparams = new Dictionary <string, ContextualLinqParameter>();

            //From x
            var fromExpr = query.FromClause.Identifier;
            //in <expr>
            var    inExpr = query.FromClause.Expression;
            string name   = fromExpr.ValueText;

            var memberExpr = inExpr as MemberAccessExpressionSyntax;

            if (memberExpr != null)
            {
                EFCodeFirstClassInfo cls;
                if (LinqExpressionValidator.MemberAccessIsAccessingDbContext(memberExpr, context, efContext, out cls))
                {
                    cparams[name] = new ContextualLinqParameter(name, cls);
                }
            }

            //Still not set, just set as a contextual parameter with no known type
            if (!cparams.ContainsKey(name))
            {
                cparams[name] = new ContextualLinqParameter(name);
            }

            return(cparams);
        }