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


C# SchemaBuilder.AddUniqueIndex方法代码示例

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


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

示例1: Start

        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<PropertyRouteEntity>();

                sb.AddUniqueIndex<PropertyRouteEntity>(p => new { p.Path, p.RootType }); 

                sb.Schema.Synchronizing += SyncronizeProperties;
            }
        }
开发者ID:JackWangCUMT,项目名称:extensions,代码行数:11,代码来源:PropertyRouteLogic.cs

示例2: Start

        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<TranslationReplacementEntity>();

                sb.AddUniqueIndex<TranslationReplacementEntity>(tr => new { tr.CultureInfo, tr.WrongTranslation });

                dqm.RegisterQuery(typeof(TranslationReplacementEntity), () =>
                   from e in Database.Query<TranslationReplacementEntity>()
                   select new
                   {
                       Entity = e,
                       e.Id,
                       e.CultureInfo,
                       e.WrongTranslation,
                       e.RightTranslation,
                   });

                new Graph<TranslationReplacementEntity>.Execute(TranslationReplacementOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { },
                }.Register();

                new Graph<TranslationReplacementEntity>.Delete(TranslationReplacementOperation.Delete)
                {
                    Delete = (e, _) => { e.Delete(); },
                }.Register();

                ReplacementsLazy = sb.GlobalLazy(() => Database.Query<TranslationReplacementEntity>()
                    .AgGroupToDictionary(a => a.CultureInfo.ToCultureInfo(),
                    gr =>
                    {
                        var dic = gr.ToDictionary(a => a.WrongTranslation, a => a.RightTranslation, StringComparer.InvariantCultureIgnoreCase, "wrong translations");

                        var regex = new Regex(dic.Keys.ToString(Regex.Escape, "|"), RegexOptions.IgnoreCase);

                        return new TranslationReplacementPack { Dictionary = dic, Regex = regex };
                    }),
                    new InvalidateWith(typeof(TranslationReplacementEntity)));

            }
        }
开发者ID:JackWangCUMT,项目名称:extensions,代码行数:45,代码来源:TranslationReplacementLogic.cs

示例3: Start

        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                FileTypeLogic.Start(sb, dqm);

                sb.Include<FilePathEntity>();

                sb.Schema.EntityEvents<FilePathEntity>().Retrieved += FilePathLogic_Retrieved;
                sb.Schema.EntityEvents<FilePathEntity>().PreSaving += FilePath_PreSaving;
                sb.Schema.EntityEvents<FilePathEntity>().PreUnsafeDelete += new PreUnsafeDeleteHandler<FilePathEntity>(FilePathLogic_PreUnsafeDelete);

                dqm.RegisterQuery(typeof(FilePathEntity), () =>
                    from p in Database.Query<FilePathEntity>()
                    select new
                    {
                        Entity = p,
                        p.Id,
                        p.FileName,
                        p.FileType,
                        p.Sufix
                    });

                new Graph<FilePathEntity>.Execute(FilePathOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (fp, _) =>
                    {
                        if (!fp.IsNew)
                        {

                            var ofp = fp.ToLite().Retrieve();


                            if (fp.FileName != ofp.FileName || fp.Sufix != ofp.Sufix || fp.FullPhysicalPath != ofp.FullPhysicalPath)
                            {
                                using (Transaction tr = new Transaction())
                                {
                                    var preSufix = ofp.Sufix.Substring(0, ofp.Sufix.Length - ofp.FileName.Length);
                                    fp.Sufix = Path.Combine(preSufix, fp.FileName);
                                    fp.Save();
                                    System.IO.File.Move(ofp.FullPhysicalPath, fp.FullPhysicalPath);
                                    tr.Commit();
                                }
                            }
                        }
                    }
                }.Register();
                

                sb.AddUniqueIndex<FilePathEntity>(f => new { f.Sufix, f.FileType }); //With mixins, add AttachToUniqueIndexes to field

                dqm.RegisterExpression((FilePathEntity fp) => fp.WebImage(), () => typeof(WebImage).NiceName(), "Image");
                dqm.RegisterExpression((FilePathEntity fp) => fp.WebDownload(), () => typeof(WebDownload).NiceName(), "Download");

            }
        }
开发者ID:rondoo,项目名称:extensions,代码行数:58,代码来源:FilePathLogic.cs


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