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


C# IEntityMapping.Get方法代码示例

本文整理汇总了C#中IEntityMapping.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IEntityMapping.Get方法的具体用法?C# IEntityMapping.Get怎么用?C# IEntityMapping.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEntityMapping的用法示例。


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

示例1: GetInsertResult

        public virtual Expression GetInsertResult(IEntityMapping mapping, Expression instance, LambdaExpression selector, Dictionary<MemberInfo, Expression> map)
        {
            var tableAlias = new TableAlias();
            var tex = new TableExpression(tableAlias, mapping);
            var aggregator = Aggregator.GetAggregator(selector.Body.Type, typeof(IEnumerable<>).MakeGenericType(selector.Body.Type));

            Expression where = null;
            DeclarationCommand genIdCommand = null;
            var generatedIds = mapping.PrimaryKeys.Where(m => m.IsPrimaryKey && m.IsGenerated).ToList();
            if (generatedIds.Count > 0)
            {
                if (map == null || !generatedIds.Any(m => map.ContainsKey(m.Member)))
                {
                    var localMap = new Dictionary<MemberInfo, Expression>();
                    genIdCommand = this.GetGeneratedIdCommand(mapping, generatedIds, localMap);
                    map = localMap;
                }

                // is this just a retrieval of one generated id member?
                var mex = selector.Body as MemberExpression;
                if (mex != null)
                {
                    var id = mapping.Get(mex.Member);
                    if (id != null && id.IsPrimaryKey && id.IsGenerated)
                    {
                        if (genIdCommand != null)
                        {
                            // just use the select from the genIdCommand
                            return new ProjectionExpression(
                                genIdCommand.Source,
                                new ColumnExpression(mex.Type, genIdCommand.Variables[0].SqlType, genIdCommand.Source.Alias, genIdCommand.Source.Columns[0].Name),
                                aggregator
                                );
                        }
                        else
                        {
                            TableAlias alias = new TableAlias();
                            var colType = id.SqlType;
                            return new ProjectionExpression(
                                new SelectExpression(alias, new[] { new ColumnDeclaration("", map[mex.Member], colType) }, null, null),
                                new ColumnExpression(mex.Member.GetMemberType(), colType, alias, ""),
                                aggregator
                                );
                        }
                    }

                    where = generatedIds.Select((m, i) =>
                        this.GetMemberExpression(tex, mapping, m.Member).Equal(map[m.Member])
                        ).Aggregate((x, y) => x.And(y));
                }
            }
            else
            {
                where = this.GetIdentityCheck(tex, mapping, instance);
            }

            Expression typeProjector = this.GetEntityExpression(tex, mapping);
            Expression selection = DbExpressionReplacer.Replace(selector.Body, selector.Parameters[0], typeProjector);
            TableAlias newAlias = new TableAlias();
            var pc = ColumnProjector.ProjectColumns(selection, null, newAlias, tableAlias);
            var pe = new ProjectionExpression(
                new SelectExpression(newAlias, pc.Columns, tex, where),
                pc.Projector,
                aggregator
                );

            if (genIdCommand != null)
            {
                return new BlockCommand(genIdCommand, pe);
            }
            return pe;
        }
开发者ID:jaykizhou,项目名称:elinq,代码行数:72,代码来源:DbExpressionBuilder.cs

示例2: GetMemberExpression

 public Expression GetMemberExpression(Expression root, IEntityMapping mapping, MemberInfo member)
 {
     return GetMemberExpression(root, mapping, mapping.Get(member));
 }
开发者ID:jaykizhou,项目名称:elinq,代码行数:4,代码来源:DbExpressionBuilder.cs

示例3: GetMemberExpression

 public Expression GetMemberExpression(Expression root, IEntityMapping entity, MemberInfo member)
 {
     return GetMemberExpression(root, entity, entity.Get(member));
 }
开发者ID:CMONO,项目名称:elinq,代码行数:4,代码来源:DbExpressionBuilder.cs


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