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


C# IClassMapper类代码示例

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


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

示例1: SelectSet

        public string SelectSet(IClassMapper classMap, IPredicate predicate, IList<ISort> sort, int firstResult, int maxResults, IDictionary<string, object> parameters)
        {
            if (sort == null || !sort.Any())
            {
                throw new ArgumentNullException("Sort", "Sort cannot be null or empty.");
            }

            if (parameters == null)
            {
                throw new ArgumentNullException("Parameters");
            }

            StringBuilder innerSql = new StringBuilder(string.Format("SELECT {0} FROM {1}",
                BuildSelectColumns(classMap),
                GetTableName(classMap)));
            if (predicate != null)
            {
                innerSql.Append(" WHERE ")
                    .Append(predicate.GetSql(this, parameters));
            }

            string orderBy = sort.Select(s => GetColumnName(classMap, s.PropertyName, false) + (s.Ascending ? " ASC" : " DESC")).AppendStrings();
            innerSql.Append(" ORDER BY " + orderBy);

            string sql = Configuration.Dialect.GetSetSql(innerSql.ToString(), firstResult, maxResults, parameters);
            return sql;
        }
开发者ID:FlowWithCaptainJack,项目名称:Dapper.Extensions.Linq,代码行数:27,代码来源:SqlGeneratorImpl.cs

示例2: GetPredicate

        public static IPredicate GetPredicate(IClassMapper classMap, object predicate)
        {
            var wherePredicate = predicate as IPredicate;
            if (wherePredicate == null && predicate != null)
            {
                Type predicateType = typeof(FieldPredicate<>).MakeGenericType(classMap.EntityType);
                IList<IPredicate> predicates = new List<IPredicate>();
                foreach (var kvp in ReflectionHelper.GetObjectValues(predicate))
                {
                    var fieldPredicate = Activator.CreateInstance(predicateType) as IFieldPredicate;
                    fieldPredicate.Not = false;
                    fieldPredicate.Operator = Operator.Eq;
                    fieldPredicate.PropertyName = kvp.Key;
                    fieldPredicate.Value = kvp.Value;
                    predicates.Add(fieldPredicate);
                }

                return predicates.Count == 1
                           ? predicates[0]
                           : new PredicateGroup
                           {
                               Operator = GroupOperator.And,
                               Predicates = predicates
                           };
            }

            return wherePredicate;
        }
开发者ID:githubbylf,项目名称:FreshFruit,代码行数:28,代码来源:DbOperatorExtensions.cs

示例3: FileSystemItemCustomization

        void FileSystemItemCustomization(IClassMapper<FileSystemItem> ca)
        {
            ca.Table(tablePrefix + "FSItem");
            ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); });
            ca.Lazy(false);
            ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); });

            ca.Component(x => x.Path, cm =>
            {
                cm.Property(x => x.Parent, ccm => { ccm.Length(1024); });
                cm.Property(x => x.Name, ccm => { ccm.Length(255); });
                cm.Property(x => x.IsDirectory, ccm => { });
            });
            ca.Property(x => x.Created, cm => { cm.NotNullable(true); });
            ca.Property(x => x.Updated, cm => { cm.NotNullable(true); });
            ca.Property(x => x.Length, cm => { });
            //ca.Bag(x => x.Chunks, cm =>
            //    {
            //        cm.Key(k => k.Column("FileID"));
            //        cm.Inverse(true);
            //        cm.Cascade(Cascade.All);
            //        cm.OrderBy(ci => ci.Offset);
            //        cm.Lazy(CollectionLazy.Extra);
            //    }, cr => cr.OneToMany());
        }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:25,代码来源:FileConfigurationParticipator.cs

示例4: BuildSelectColumns

 public virtual string BuildSelectColumns(IClassMapper classMap)
 {
     var columns = classMap.Properties
         .Where(p => !p.Ignored)
         .Select(p => GetColumnName(classMap, p, true));
     return columns.AppendStrings();
 }
开发者ID:rpaschoal,项目名称:Dapper-Extensions,代码行数:7,代码来源:SqlGenerator.cs

示例5: BucketCustomization

		private void BucketCustomization(IClassMapper<Bucket> ca)
		{
			ca.Table(tablePrefix + "StatisticsBucket");
			ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); });
			ca.Lazy(false);
			ca.Property(x => x.PageID, cm => { cm.NotNullable(true); });
			ca.Property(x => x.TimeSlot, cm => { cm.NotNullable(true); });
			ca.Property(x => x.Views, cm => { cm.NotNullable(true); });
		}
开发者ID:rukmareddy,项目名称:n2cms,代码行数:9,代码来源:StatisticsTablesParticipator.cs

示例6: FileSystemChunkCustomization

 void FileSystemChunkCustomization(IClassMapper<FileSystemChunk> ca)
 {
     ca.Table(tablePrefix + "FSChunk");
     ca.Lazy(false);
     ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); });
     ca.ManyToOne(x => x.BelongsTo, m => { m.Column("FileID"); });
     ca.Property(x => x.Offset, cm => { });
     ca.Property(cm => cm.Data, cm => { cm.Type(NHibernateUtil.BinaryBlob); cm.Length(ConfigurationBuilder.BlobLength); cm.Lazy(false); });
 }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:9,代码来源:FileConfigurationParticipator.cs

示例7: Create

        public override string Create(IClassMapper classMap)
        {
            var columns = classMap.Properties.Where(p => !(p.Ignored || p.IsReadOnly)).ToArray();

            if (!columns.Any())
            {
                throw new ArgumentException("No columns were mapped.");
            }

            var columnKeys = columns.Select(p => new KeyValuePair<Type, string>(p.PropertyInfo.PropertyType, GetColumnName(classMap, p, false)))
                      .ToList();
            var sql = new StringBuilder();

            sql.AppendFormat("CREATE TABLE IF NOT EXISTS {0}", GetTableName(classMap)).AppendLine();
            sql.AppendLine("(");

            var index = 0;
            var pk = String.Empty;

            foreach (var columnKey in columnKeys)
            {
                var column = columns.FirstOrDefault(f => columnKey.Key == f.PropertyInfo.PropertyType &&
                    columnKey.Value.IndexOf(f.Name, StringComparison.InvariantCultureIgnoreCase) >= 0);

                if (column == null)
                    continue;

                switch (column.KeyType)
                {
                    case KeyType.Identity:
                        pk = columnKey.Value;
                        sql.AppendFormat("{0} {1} NOT NULL AUTO_INCREMENT",
                            pk, Configuration.DataMapper[columnKey.Key]);

                        break;
                    default:
                        sql.AppendFormat("{0} {1} NULL",
                                 columnKey.Value, Configuration.DataMapper[columnKey.Key]);
                        break;
                }

                sql.Append(",")
                    .AppendLine();

                index++;
            }

            if (!String.IsNullOrWhiteSpace(pk))
            {
                sql.AppendFormat(" PRIMARY KEY ({0})", pk)
                    .AppendLine();
            }

            sql.AppendLine(")");

            return sql.ToString();
        }
开发者ID:git00n1,项目名称:DapperRepository,代码行数:57,代码来源:MySqlGenerator.cs

示例8: Delete

        public string Delete(IClassMapper classMap, IPredicate predicate, IDictionary<string, object> parameters)
        {
            StringBuilder sql = new StringBuilder(string.Format("DELETE FROM {0}", GetTableName(classMap)));
            if (predicate != null)
            {
                sql.Append(" WHERE ")
                    .Append(predicate.GetSql(parameters));
            }

            return sql.ToString();
        }
开发者ID:kenchilada,项目名称:Dapper-Extensions,代码行数:11,代码来源:SqlGenerator.cs

示例9: Create

        public override string Create(IClassMapper classMap)
        {
            var columns = classMap.Properties.Where(p => !(p.Ignored || p.IsReadOnly)).ToArray();

            if (!columns.Any())
            {
                throw new ArgumentException("No columns were mapped.");
            }

            var columnKeys = columns.Select(p => new KeyValuePair<Type, string>(p.PropertyInfo.PropertyType, GetColumnName(classMap, p, false)))
                    .ToList();
            var sql = new StringBuilder();

            sql.AppendFormat(@"IF (OBJECT_ID('{0}', 'U') IS NULL)", GetTableName(classMap))
                .AppendLine();
            sql.AppendFormat("CREATE TABLE {0}", GetTableName(classMap)).AppendLine();
            sql.AppendLine("(");

            var index = 0;
            foreach (var columnKey in columnKeys)
            {
                var column = columns.FirstOrDefault(f => columnKey.Key == f.PropertyInfo.PropertyType &&
                   columnKey.Value.IndexOf(f.Name, StringComparison.InvariantCultureIgnoreCase) >= 0);

                if (column == null)
                    continue;

                if (index > 0)
                    sql.Append(",");

                switch (column.KeyType)
                {
                    case KeyType.Identity:
                        sql.AppendFormat("{0} {1} NOT NULL IDENTITY(1,1) PRIMARY KEY",
                            columnKey.Value,
                            Configuration.DataMapper[columnKey.Key]);
                        break;
                    default:
                        sql.AppendFormat("{0} {1} NULL",
                                columnKey.Value,
                                 Configuration.DataMapper[columnKey.Key]);
                        break;
                }

                sql.AppendLine();
                index++;
            }

            sql.AppendLine(")");

            return sql.ToString();
        }
开发者ID:git00n1,项目名称:DapperRepository,代码行数:52,代码来源:SqlServerGenerator.cs

示例10: StatisticCustomization

		private void StatisticCustomization(IClassMapper<Statistic> ca)
		{
			ca.Table(tablePrefix + "Statistics");
			ca.ComposedId(x =>
			{
				x.Property(y => y.TimeSlot);
				x.Property(y => y.PageID);
			});
			//ca.Id(x => new { x.TimeSlot, x.PageID }, cm => { cm.Generator(Generators.Assigned); });
			ca.Lazy(false);
			ca.Property(x => x.TimeSlot, cm => { cm.NotNullable(true); });
			ca.Property(x => x.Views, cm => { cm.NotNullable(true); });
		}
开发者ID:rukmareddy,项目名称:n2cms,代码行数:13,代码来源:StatisticsTablesParticipator.cs

示例11: Delete

        public virtual string Delete(IClassMapper classMap, IPredicate predicate, IDictionary<string, object> parameters)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException("Predicate");
            }

            if (parameters == null)
            {
                throw new ArgumentNullException("Parameters");
            }

            var sql = new StringBuilder(string.Format("DELETE FROM {0}", GetTableName(classMap)));
            sql.Append(" WHERE ").Append(predicate.GetSql(this, parameters));
            return sql.ToString();
        }
开发者ID:git00n1,项目名称:DapperRepository,代码行数:16,代码来源:SqlGenerator.cs

示例12: Count

        public virtual string Count(IClassMapper classMap, IPredicate predicate, IDictionary<string, object> parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("Parameters");
            }

            StringBuilder sql = new StringBuilder(string.Format("SELECT COUNT(*) AS {0}Total{1} FROM {2}",
                                Configuration.Dialect.OpenQuote,
                                Configuration.Dialect.CloseQuote,
                                GetTableName(classMap)));
            if (predicate != null)
            {
                sql.Append(" WHERE ")
                    .Append(predicate.GetSql(this, parameters));
            }

            return sql.ToString();
        }
开发者ID:rpaschoal,项目名称:Dapper-Extensions,代码行数:19,代码来源:SqlGenerator.cs

示例13: Select

        public string Select(IClassMapper classMap, IPredicate predicate, IList<ISort> sort, IDictionary<string, object> parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("Parameters");
            }

            StringBuilder sql = new StringBuilder(string.Format("SELECT {0} FROM {1}",
                BuildSelectColumns(classMap),
                GetTableName(classMap)));
            if (predicate != null)
            {
                sql.Append(" WHERE ")
                    .Append(predicate.GetSql(this, parameters));
            }

            if (sort != null && sort.Any())
            {
                sql.Append(" ORDER BY ")
                    .Append(sort.Select(s => GetColumnName(classMap, s.PropertyName, false) + (s.Ascending ? " ASC" : " DESC")).AppendStrings());
            }

            return sql.ToString();
        }
开发者ID:FlowWithCaptainJack,项目名称:Dapper.Extensions.Linq,代码行数:24,代码来源:SqlGeneratorImpl.cs

示例14: ContentItemCustomization

		void ContentItemCustomization(IClassMapper<ContentItem> ca)
		{
			ca.Table(tablePrefix + "Item");
			ca.Lazy(false);
			ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); });
			ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); });
			ca.Discriminator(cm => { cm.Column("Type"); cm.Type(NHibernateUtil.String); });
			ca.Property(x => x.Created, cm => { });
			ca.Property(x => x.Published, cm => { });
			ca.Property(x => x.Updated, cm => { });
			ca.Property(x => x.Expires, cm => { });
			ca.Property(x => x.Name, cm => { cm.Length(250); });
			ca.Property(x => x.ZoneName, cm => { cm.Length(50); });
			ca.Property(x => x.TemplateKey, cm => { cm.Length(50); });
			ca.Property(x => x.TranslationKey, cm => { });
			ca.Property(x => x.Title, cm => { cm.Length(250); });
			ca.Property(x => x.SortOrder, cm => { });
			ca.Property(x => x.Visible, cm => { });
			ca.Property(x => x.SavedBy, cm => { cm.Length(50); });
			ca.Property(x => x.State, cm => { });
			ca.Property(x => x.ChildState, cm => { });
			ca.Property(x => x.AncestralTrail, cm => { cm.Length(100); });
			ca.Property(x => x.VersionIndex, cm => { });
			ca.Property(x => x.AlteredPermissions, cm => { });
			//ca.ManyToOne(x => x.VersionOf, cm => { cm.Column("VersionOfID"); cm.Lazy(LazyRelation.Proxy); cm.Fetch(FetchKind.Select); });
			//ca.Property(x => x.VersionOf, cm =>
			//{
			//    cm.Column("VersionOfID");
			//    cm.Type<ContentRelationFactory>();
			//});
			ca.Component(x => x.VersionOf, cm =>
			{
				cm.Property(cr => cr.ID, pm => pm.Column("VersionOfID"));
			});
			ca.ManyToOne(x => x.Parent, cm => { cm.Column("ParentID"); cm.Lazy(LazyRelation.Proxy); cm.Fetch(FetchKind.Select); });
			ca.Bag(x => x.Children, cm =>
			{
				cm.Key(k => k.Column("ParentID"));
				cm.Inverse(true);
				cm.Type<ContentItemListFactory<ContentItem>>();
				cm.Cascade(childrenCascade);
				cm.OrderBy(ci => ci.SortOrder);
				cm.Lazy(childrenLaziness);
				if (childrenBatch)
					cm.BatchSize(batchSize ?? 10);
				cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); });
			}, cr => cr.OneToMany());
			ca.Bag(x => x.Details, cm =>
			{
				cm.Key(k => k.Column("ItemID"));
				cm.Inverse(true);
				cm.Type<ContentListFactory<ContentDetail>>();
				cm.Cascade(Cascade.All | Cascade.DeleteOrphans);
				cm.Fetch(CollectionFetchMode.Select);
				cm.Lazy(CollectionLazy.Lazy);
				cm.BatchSize(batchSize ?? 10);
				cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); });
				cm.Where("DetailCollectionID IS NULL");
			}, cr => cr.OneToMany());
			ca.Bag(x => x.DetailCollections, cm =>
			{
				cm.Key(k => k.Column("ItemID"));
				cm.Inverse(true);
				cm.Type<ContentListFactory<DetailCollection>>();
				cm.Cascade(Cascade.All | Cascade.DeleteOrphans);
				cm.Fetch(CollectionFetchMode.Select);
				cm.Lazy(CollectionLazy.Lazy);
				cm.BatchSize(batchSize ?? 10);
				cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); });
			}, cr => cr.OneToMany());
			ca.Bag(x => x.AuthorizedRoles, cm =>
			{
				cm.Key(k => k.Column("ItemID"));
				cm.Inverse(true);
				cm.Cascade(Cascade.All | Cascade.DeleteOrphans);
				cm.Fetch(CollectionFetchMode.Select);
				cm.Lazy(CollectionLazy.Lazy);
				cm.BatchSize(batchSize ?? 25);
				cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); });
			}, cr => cr.OneToMany());
		}
开发者ID:nagarjunachallapalli,项目名称:n2cms,代码行数:81,代码来源:ConfigurationBuilder.cs

示例15: Update

        public virtual string Update(IClassMapper classMap, IPredicate predicate, IDictionary<string, object> parameters)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException("Predicate");
            }

            if (parameters == null)
            {
                throw new ArgumentNullException("Parameters");
            }

            var columns = classMap.Properties.Where(p => !(p.Ignored || p.IsReadOnly || p.KeyType == KeyType.Identity));
            if (!columns.Any())
            {
                throw new ArgumentException("No columns were mapped.");
            }

            var setSql =
                columns.Select(
                    p =>
                    string.Format(
                        "{0} = {1}{2}", GetColumnName(classMap, p, false), Configuration.Dialect.ParameterPrefix, p.Name));

            return string.Format("UPDATE {0} SET {1} WHERE {2}",
                GetTableName(classMap),
                setSql.AppendStrings(),
                predicate.GetSql(this, parameters));
        }
开发者ID:rpaschoal,项目名称:Dapper-Extensions,代码行数:29,代码来源:SqlGenerator.cs


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