当前位置: 首页>>代码示例>>C#>>正文


C# DbPropertyExpression类代码示例

本文整理汇总了C#中DbPropertyExpression的典型用法代码示例。如果您正苦于以下问题:C# DbPropertyExpression类的具体用法?C# DbPropertyExpression怎么用?C# DbPropertyExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DbPropertyExpression类属于命名空间,在下文中一共展示了DbPropertyExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Visit

 public override VisitedExpression Visit(DbPropertyExpression expression)
 {
     DbVariableReferenceExpression variable = expression.Instance as DbVariableReferenceExpression;
     if (variable == null || variable.VariableName != _projectVarName.Peek())
         throw new NotSupportedException();
     return new PropertyExpression(expression.Property);
 }
开发者ID:cody82,项目名称:spacewar-arena,代码行数:7,代码来源:SqlUpdateGenerator.cs

示例2: Visit

        public override VisitedExpression Visit(DbPropertyExpression expression)
        {
            /*
             * Algorithm for finding the correct reference expression: "Collection"."Name"
             * The collection is always a leaf InputExpression, found by lookup in _refToNode.
             * The name for the collection is found using node.TopName.
             *
             * We must now follow the path from the leaf down to the root,
             * and make sure the column is projected all the way down.
             *
             * We need not project columns at a current InputExpression.
             * For example, in
             *  SELECT ? FROM <from> AS "X" WHERE "X"."field" = <value>
             * we use the property "field" but it should not be projected.
             * Current expressions are stored in _currentExpressions.
             * There can be many of these, for example if we are in a WHERE EXISTS (SELECT ...) or in the right hand side of an Apply expression.
             *
             * At join nodes, column names might have to be renamed, if a name collision occurs.
             * For example, the following would be illegal,
             *  SELECT "X"."A" AS "A", "Y"."A" AS "A" FROM (SELECT 1 AS "A") AS "X" CROSS JOIN (SELECT 1 AS "A") AS "Y"
             * so we write
             *  SELECT "X"."A" AS "A", "Y"."A" AS "A_Alias<N>" FROM (SELECT 1 AS "A") AS "X" CROSS JOIN (SELECT 1 AS "A") AS "Y"
             * The new name is then propagated down to the root.
             */

            string name = expression.Property.Name;
            string from = (expression.Instance.ExpressionKind == DbExpressionKind.Property)
                ? ((DbPropertyExpression)expression.Instance).Property.Name
                : ((DbVariableReferenceExpression)expression.Instance).VariableName;

            PendingProjectsNode node = _refToNode[from];
            from = node.TopName;
            while (node != null)
            {
                foreach (var item in node.Selects)
                {
                    if (_currentExpressions.Contains(item.Exp))
                        continue;

                    var use = new StringPair(from, name);

                    if (!item.Exp.ColumnsToProject.ContainsKey(use))
                    {
                        var oldName = name;
                        while (item.Exp.ProjectNewNames.Contains(name))
                            name = oldName + "_" + NextAlias();
                        item.Exp.ColumnsToProject[use] = name;
                        item.Exp.ProjectNewNames.Add(name);
                    }
                    else
                    {
                        name = item.Exp.ColumnsToProject[use];
                    }
                    from = item.AsName;
                }
                node = node.JoinParent;
            }
            return new ColumnReferenceExpression { Variable = from, Name = name };
        }
开发者ID:Emill,项目名称:Npgsql,代码行数:59,代码来源:SqlSelectGenerator.cs

示例3: Visit

 public override VisitedExpression Visit(DbPropertyExpression expression)
 {
     // not quite sure what this does
     // may be . notation for seperating
     // scopes (such as schema.table.column)
     //VisitedExpression variable = expression.Instance.Accept(this);
     VariableReferenceExpression variable = new VariableReferenceExpression(expression.Instance.Accept(this).ToString(), _variableSubstitution);
     return new PropertyExpression(variable, expression.Property);
 }
开发者ID:baondp,项目名称:Npgsql,代码行数:9,代码来源:SqlSelectGenerator.cs

示例4: DiscriminatorMap

 private DiscriminatorMap(DbPropertyExpression discriminator,
     List<KeyValuePair<object, EntityType>> typeMap,
     Dictionary<EdmProperty, DbExpression> propertyMap,
     Dictionary<Query.InternalTrees.RelProperty, DbExpression> relPropertyMap,
     EntitySet entitySet)
 {
     this.Discriminator = discriminator;
     this.TypeMap = typeMap.AsReadOnly();
     this.PropertyMap = propertyMap.ToList().AsReadOnly();
     this.RelPropertyMap = relPropertyMap.ToList().AsReadOnly();
     this.EntitySet = entitySet;
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:12,代码来源:DiscriminatorMap.cs

示例5: DiscriminatorMap

 private DiscriminatorMap(
     DbPropertyExpression discriminator,
     List<KeyValuePair<object, EntityType>> typeMap,
     Dictionary<EdmProperty, DbExpression> propertyMap,
     Dictionary<RelProperty, DbExpression> relPropertyMap,
     EntitySet entitySet)
 {
     Discriminator = discriminator;
     TypeMap = typeMap.AsReadOnly();
     PropertyMap = propertyMap.ToList().AsReadOnly();
     RelPropertyMap = relPropertyMap.ToList().AsReadOnly();
     EntitySet = entitySet;
 }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:13,代码来源:DiscriminatorMap.cs

示例6: DiscriminatorMap

 private DiscriminatorMap(
     DbPropertyExpression discriminator,
     List<KeyValuePair<object, EntityType>> typeMap,
     Dictionary<EdmProperty, DbExpression> propertyMap,
     Dictionary<RelProperty, DbExpression> relPropertyMap,
     EntitySet entitySet)
 {
     Discriminator = discriminator;
     TypeMap = new ReadOnlyCollection<KeyValuePair<object, EntityType>>(typeMap);
     PropertyMap = new ReadOnlyCollection<KeyValuePair<EdmProperty, DbExpression>>(propertyMap.ToList());
     RelPropertyMap = new ReadOnlyCollection<KeyValuePair<RelProperty, DbExpression>>(relPropertyMap.ToList());
     EntitySet = entitySet;
 }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:13,代码来源:DiscriminatorMap.cs

示例7: Visit

        public override Expression Visit(DbPropertyExpression expression)
        {
            string propertyName = expression.Property.GetColumnName();

            Expression sourceExpression = this.Visit(expression.Instance);
            Expression result = Expression.Property(sourceExpression, propertyName);

            // Every property access result is nullable in SQL
            // Check if the propery type is not nullable
            if (result.Type.IsValueType && !TypeHelper.IsNullable(result.Type))
            {
                // Make it nullable
                result = Expression.Convert(result, TypeHelper.MakeNullable(result.Type));
            }

            return result;
        }
开发者ID:DeadlyEmbrace,项目名称:effort,代码行数:17,代码来源:TransformVisitor.Property.cs

示例8: Visit

 public override VisitedExpression Visit(DbPropertyExpression expression)
 {
     DbVariableReferenceExpression variable = expression.Instance as DbVariableReferenceExpression;
     if (variable == null || variable.VariableName != _projectVarName.Peek())
         throw new NotSupportedException();
     if (!_processingReturning)
     {
         return new PropertyExpression(expression.Property);
     }
     else
     {
         // the table name needs to be quoted, the column name does not.
         // http://archives.postgresql.org/pgsql-bugs/2007-01/msg00102.php
         string tableName = QuoteIdentifier(_variableSubstitution[variable.VariableName]);
         if (variable.VariableName == _commandTree.Target.VariableName)
         {
             // try to get the table name schema qualified.
             DbScanExpression scan = _commandTree.Target.Expression as DbScanExpression;
             if (scan != null)
             {
     #if ENTITIES6
                 System.Data.Entity.Core.Metadata.Edm.MetadataProperty metadata;
     #else
                 System.Data.Metadata.Edm.MetadataProperty metadata;
     #endif
                 string overrideSchema = "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator:Schema";
                 if (scan.Target.MetadataProperties.TryGetValue(overrideSchema, false, out metadata) && metadata.Value != null)
                 {
                     tableName = QuoteIdentifier(metadata.Value.ToString()) + "." + tableName;
                 }
                 else if (scan.Target.MetadataProperties.TryGetValue("Schema", false, out metadata) && metadata.Value != null)
                 {
                     tableName = QuoteIdentifier(metadata.Value.ToString()) + "." + tableName;
                 }
                 else
                 {
                     tableName = QuoteIdentifier(scan.Target.EntityContainer.Name) + "." + tableName;
                 }
             }
         }
         return new LiteralExpression("currval(pg_get_serial_sequence('" + tableName + "', '" + expression.Property.Name + "'))");
     }
 }
开发者ID:kristofen,项目名称:Npgsql,代码行数:43,代码来源:SqlInsertGenerator.cs

示例9: Visit

 public override void Visit(DbPropertyExpression e)
 {
     e.Instance.Accept(this);
     VisitExprKind(e.ExpressionKind);
     _key.Append(e.Property.Name);
 }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:6,代码来源:ExpressionKeyGen.cs

示例10: Visit

            public override DbExpression Visit(DbPropertyExpression expression)
            {
                DbExpression result = null;

                DbExpression replacementValue;
                if (expression.Instance.ExpressionKind == DbExpressionKind.VariableReference &&
                    (((DbVariableReferenceExpression)expression.Instance).VariableName == this.variableName) &&
                    this.replacements.TryGetValue(expression.Property.Name, out replacementValue))
                {
                    result = replacementValue;
                }
                else
                {
                    result = base.Visit(expression);
                }
                return result;
            }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:17,代码来源:ViewSimplifier.cs

示例11: HasMatchInList

 /// <summary>
 /// Helper method for <see cref="RemoveNonSortProperties"/>
 /// Checks whether expr has a 'match' in the given list of property expressions. 
 /// If it does, the matching expression is removed form the list, to speed up future matching.
 /// </summary>
 /// <param name="expr"></param>
 /// <param name="sortList"></param>
 /// <param name="exprBindingVariableName"></param>
 /// <param name="sortExpressionsBindingVariableName"></param>
 /// <returns></returns>
 private static bool HasMatchInList(
     DbPropertyExpression expr, IList<DbPropertyExpression> list, string exprBindingVariableName,
     string listExpressionsBindingVariableName)
 {
     for (var i = 0; i < list.Count; i++)
     {
         if (AreMatching(expr, list[i], exprBindingVariableName, listExpressionsBindingVariableName))
         {
             // This method is used for matching element of two list without duplicates,
             // thus if match is found, remove it from the list, to speed up future matching.
             list.RemoveAt(i);
             return true;
         }
     }
     return false;
 }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:26,代码来源:Sql8ExpressionRewriter.cs

示例12: AreMatching

        /// <summary>
        /// Determines whether two expressions match. 
        /// They match if they are  of the shape 
        ///   expr1 -> DbPropertyExpression(... (DbPropertyExpression(DbVariableReferenceExpression(expr1BindingVariableName), nameX), ..., name1)
        ///   expr1 -> DbPropertyExpression(... (DbPropertyExpression(DbVariableReferenceExpression(expr2BindingVariableName), nameX), ..., name1),
        ///   
        /// i.e. if they only differ in the name of the binding.  
        /// </summary>
        /// <param name="expr1"></param>
        /// <param name="expr2"></param>
        /// <param name="expr1BindingVariableName"></param>
        /// <param name="expr2BindingVariableName"></param>
        /// <returns></returns>
        private static bool AreMatching(
            DbPropertyExpression expr1, DbPropertyExpression expr2, string expr1BindingVariableName, string expr2BindingVariableName)
        {
            if (expr1.Property.Name
                != expr2.Property.Name)
            {
                return false;
            }

            if (expr1.Instance.ExpressionKind
                != expr2.Instance.ExpressionKind)
            {
                return false;
            }

            if (expr1.Instance.ExpressionKind
                == DbExpressionKind.Property)
            {
                return AreMatching(
                    (DbPropertyExpression)expr1.Instance, (DbPropertyExpression)expr2.Instance, expr1BindingVariableName,
                    expr2BindingVariableName);
            }

            var instance1 = (DbVariableReferenceExpression)expr1.Instance;
            var instance2 = (DbVariableReferenceExpression)expr2.Instance;

            return (String.Equals(instance1.VariableName, expr1BindingVariableName, StringComparison.Ordinal)
                    && String.Equals(instance2.VariableName, expr2BindingVariableName, StringComparison.Ordinal));
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:42,代码来源:Sql8ExpressionRewriter.cs

示例13: Visit

 public override void Visit(DbPropertyExpression expression) { }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:1,代码来源:DbExpressionVisitorTests.cs

示例14: Visit

		public override void Visit(DbPropertyExpression expression)
		{
			commandText.Append(DmlSqlGenerator.GenerateMemberSql(expression.Property));
		}
开发者ID:Outlivier,项目名称:FirebirdSql.Data.FirebirdClient,代码行数:4,代码来源:ExpressionTranslator.cs

示例15: Visit

        //  This is called for any navigation property reference so we can apply filters for those entities here.
        //  That includes any navigation properties referenced in functions (.Where() clauses) and also any
        //  child entities that are .Include()'d.
        public override DbExpression Visit(DbPropertyExpression expression)
        {
#if DEBUG_VISITS
            System.Diagnostics.Debug.Print("Visit(DbPropertyExpression): EdmType.Name={0}", expression.ResultType.ModelTypeUsage.EdmType.Name);
#endif
            var baseResult = base.Visit(expression);

            var basePropertyResult = baseResult as DbPropertyExpression;
            if (basePropertyResult == null)
                return baseResult;      //  base.Visit changed type!

            var navProp = basePropertyResult.Property as NavigationProperty;
            if (navProp != null)
            {
                var targetEntityType = navProp.ToEndMember.GetEntityType();

                var containers = _ObjectContext.MetadataWorkspace.GetItems<EntityContainer>(DataSpace.CSpace).First();
                var filterList = FindFiltersForEntitySet(targetEntityType.MetadataProperties);

                if (filterList.Any())
                {
                    //  If the expression contains a collection (i.e. the child property is an IEnumerable), we can bind directly to it.
                    //  Otherwise, we have to create a DbScanExpression over the ResultType in order to bind.
                    if (baseResult.ResultType.EdmType.BuiltInTypeKind == BuiltInTypeKind.CollectionType)
                    {
                        var binding = DbExpressionBuilder.Bind(baseResult);
                        var newFilterExpression = BuildFilterExpressionWithDynamicFilters(filterList, binding, null);
                        if (newFilterExpression != null)
                        {
                            //  If not null, a new DbFilterExpression has been created with our dynamic filters.
                            return newFilterExpression;
                        }
                    }
                    else if (baseResult.ResultType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType)
                    {
                        if (DoesNotSupportElementMethod(_DbContext))
                        {
                            //  Oracle and MySQL do not support the "newFilterExpression.Element()" method that we need to call 
                            //  at the end of this block.  Oracle *MAY* support it in a newer release but not sure
                            //  (see https://community.oracle.com/message/10168766#10168766).
                            //  But users may not have the option of upgrading their database so decided to try to support it.
                            //  If we find it is supported by newer versions, can detect those versions and allow the normal handling.
                            //  To apply any necessary filters to these entities, we're going to have to do it using SSpace.
                            //  These entities will be visited via the DbScan visit method so we will apply filters there.
                            //  If one of those filters then references a child property, the filter will fail.
                            return baseResult;
                        }

                        DbExpression scanExpr;

                        var entitySet = containers.EntitySets.FirstOrDefault(e => e.ElementType.Name == baseResult.ResultType.EdmType.Name);
                        if (entitySet == null)
                        {
                            if (baseResult.ResultType.EdmType.BaseType == null)
                                throw new ApplicationException(string.Format("EntitySet not found for {0}", baseResult.ResultType.EdmType.Name));

                            //  Did not find the entity set for the property but it has a base type.
                            //  This means the entity set of the property is a derived class of a TPT base class.
                            //  Find the entity set of the parent and then map it to the type we need.
                            //  Then we can bind against that expression.
                            entitySet = containers.EntitySets.FirstOrDefault(e => e.ElementType.Name == baseResult.ResultType.EdmType.BaseType.Name);
                            if (entitySet == null)        //  hope we don't need to do this recursively...
                                throw new ApplicationException(string.Format("EntitySet not found for {0} or BaseType {1}", baseResult.ResultType.EdmType.Name, baseResult.ResultType.EdmType.BaseType.Name));

                            var parentScanExpr = DbExpressionBuilder.Scan(entitySet);
                            scanExpr = DbExpressionBuilder.OfType(parentScanExpr, baseResult.ResultType);
                        }
                        else
                            scanExpr = DbExpressionBuilder.Scan(entitySet);

                        var binding = DbExpressionBuilder.Bind(scanExpr);

                        //  Build the join conditions that are needed to join from the source object (basePropertyResult.Instance)
                        //  to the child object (the scan expression we just creating the binding for).
                        //  These conditions will be and'd with the filter conditions.
                        var associationType = navProp.RelationshipType as AssociationType;
                        if (associationType == null)
                            throw new ApplicationException(string.Format("Unable to find AssociationType on navigation property of single child property {0} in type {1}", navProp.Name, navProp.DeclaringType.FullName));
                        if (associationType.Constraint == null)
                        {
                            //  KNOWN_ISSUE:
                            //  If this happens, the model does not contain the foreign key (the "id" property).  EF will automatically generate
                            //  it based on naming rules when generating the SSpace/database models but does not expose the Constraint here in the
                            //  AssociationType.  In order for us to be able to generate the conditions correctly, those Foreign Keys need to be
                            //  specified on the model.  To fix/handle this, we would need to examine the SSpace Association Sets (which do have
                            //  these relations!!) to try to map that information back to CSpace to figure out the correct properties of the FK conditions.
                            //  or...the models just need to contain the necessary "ID" properties for the FK relations so that they are available here
                            //  (in CSpace) for us to generate the necessary join conditions.
                            throw new ApplicationException(string.Format("FK Constriant not found for association '{0}' - must directly specify foreign keys on model to be able to apply this filter", associationType.FullName));
                        }

                        //  Figure out if the "baseResults" are the from side or to side of the constraint so we can create the properties correctly
                        //  Note that this navigation property may be the same type as parent entity (so both association types
                        //  will be the same type).  In that case, we need to figure out which side of the association matches the
                        //  PKs of the main entity.
                        var fromEdmType = ((AssociationEndMember)associationType.Constraint.FromRole).GetEntityType();
                        var toEdmType = ((AssociationEndMember)associationType.Constraint.ToRole).GetEntityType();
//.........这里部分代码省略.........
开发者ID:jcachat,项目名称:EntityFramework.DynamicFilters,代码行数:101,代码来源:DynamicFilterQueryVisitorCSpace.cs


注:本文中的DbPropertyExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。