IncludeFunction() static private method

static private IncludeFunction ( SchemaAssets assets ) : void
assets Signum.Engine.Maps.SchemaAssets
return void
Esempio n. 1
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                if (!Schema.Current.Settings.TypeValues.ContainsKey(typeof(TimeSpan)))
                {
                    sb.Settings.FieldAttributes((AlbumEntity a) => a.Songs[0].Duration).Add(new Signum.Entities.IgnoreAttribute());
                    sb.Settings.FieldAttributes((AlbumEntity a) => a.BonusTrack.Duration).Add(new Signum.Entities.IgnoreAttribute());
                }

                sb.Include <AlbumEntity>()
                .WithExpressionFrom(dqm, (IAuthorEntity au) => Database.Query <AlbumEntity>().Where(a => a.Author == au))
                .WithQuery(dqm, () => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.Author,
                    a.Label,
                    a.Year
                });
                AlbumGraph.Register();


                sb.Include <NoteWithDateEntity>()
                .WithSave(NoteWithDateOperation.Save)
                .WithQuery(dqm, () => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Text,
                    a.Target,
                    a.CreationTime,
                });

                sb.Include <ConfigEntity>()
                .WithSave(ConfigOperation.Save);

                MinimumExtensions.IncludeFunction(sb.Schema.Assets);
                sb.Include <ArtistEntity>()
                .WithSave(ArtistOperation.Save)
                .WithQuery(dqm, () => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.IsMale,
                    a.Sex,
                    a.Dead,
                    a.LastAward,
                });

                new Graph <ArtistEntity> .Execute(ArtistOperation.AssignPersonalAward)
                {
                    Lite       = true,
                    AllowsNew  = false,
                    CanExecute = a => a.LastAward != null ? "Artist already has an award" : null,
                    Execute    = (a, para) => a.LastAward = new PersonalAwardEntity()
                    {
                        Category = "Best Artist", Year = DateTime.Now.Year, Result = AwardResult.Won
                    }.Execute(AwardOperation.Save)
                }

                .Register();

                sb.Include <BandEntity>()
                .WithQuery(dqm, () => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.LastAward,
                });

                new Graph <BandEntity> .Execute(BandOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (b, _) =>
                    {
                        using (OperationLogic.AllowSave <ArtistEntity>())
                        {
                            b.Save();
                        }
                    }
                }

                .Register();

                sb.Include <LabelEntity>()
                .WithSave(LabelOperation.Save)
                .WithQuery(dqm, () => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                });

                RegisterAwards(sb, dqm);

                dqm.RegisterQuery(typeof(IAuthorEntity), () => DynamicQueryCore.Manual(async(request, descriptions, token) =>
                {
                    var one = (from a in Database.Query <ArtistEntity>()
                               select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Artist",
                        a.Name,
                        Lonely = a.Lonely(),
                        LastAward = a.LastAward
                    })
                              .ToDQueryable(descriptions)
                              .AllQueryOperationsAsync(request, token);

                    var two = (from a in Database.Query <BandEntity>()
                               select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Band",
                        a.Name,
                        Lonely = a.Lonely(),
                        LastAward = a.LastAward
                    })
                              .ToDQueryable(descriptions)
                              .AllQueryOperationsAsync(request, token);

                    return((await one).Concat(await two).OrderBy(request.Orders).TryPaginate(request.Pagination));
                })
                                  .Column(a => a.LastAward, cl => cl.Implementations = Implementations.ByAll)
                                  .ColumnProperyRoutes(a => a.Id, PropertyRoute.Construct((ArtistEntity a) => a.Id), PropertyRoute.Construct((BandEntity a) => a.Id)),
                                  entityImplementations: Implementations.By(typeof(ArtistEntity), typeof(BandEntity)));

                Validator.PropertyValidator((NoteWithDateEntity n) => n.Text)
                .IsApplicableValidator <StringLengthValidatorAttribute>(n => Corruption.Strict);
            }
        }
Esempio n. 2
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <AlbumEntity>()
                .WithExpressionFrom((IAuthorEntity au) => au.Albums())
                .WithQuery(() => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.Author,
                    a.Label,
                    a.Year
                });
                AlbumGraph.Register();


                sb.Include <NoteWithDateEntity>()
                .WithSave(NoteWithDateOperation.Save)
                .WithQuery(() => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Text,
                    a.Target,
                    a.CreationTime,
                });

                sb.Include <ConfigEntity>()
                .WithSave(ConfigOperation.Save);

                MinimumExtensions.IncludeFunction(sb.Schema.Assets);
                sb.Include <ArtistEntity>()
                .WithSave(ArtistOperation.Save)
                .WithVirtualMList(a => a.Nominations, n => (Lite <ArtistEntity>)n.Author)
                .WithQuery(() => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.IsMale,
                    a.Sex,
                    a.Dead,
                    a.LastAward,
                });

                new Graph <ArtistEntity> .Execute(ArtistOperation.AssignPersonalAward)
                {
                    CanExecute = a => a.LastAward != null ? "Artist already has an award" : null,
                    Execute    = (a, para) => a.LastAward = new PersonalAwardEntity()
                    {
                        Category = "Best Artist", Year = DateTime.Now.Year, Result = AwardResult.Won
                    }.Execute(AwardOperation.Save)
                }

                .Register();

                sb.Include <BandEntity>()
                .WithQuery(() => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.LastAward,
                });

                new Graph <BandEntity> .Execute(BandOperation.Save)
                {
                    CanBeNew      = true,
                    CanBeModified = true,
                    Execute       = (b, _) =>
                    {
                        using (OperationLogic.AllowSave <ArtistEntity>())
                        {
                            b.Save();
                        }
                    }
                }

                .Register();

                sb.Include <LabelEntity>()
                .WithSave(LabelOperation.Save)
                .WithQuery(() => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                });


                sb.Include <FolderEntity>()
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name
                });

                RegisterAwards(sb);

                QueryLogic.Queries.Register(typeof(IAuthorEntity), () => DynamicQueryCore.Manual(async(request, description, cancellationToken) =>
                {
                    var one = await(from a in Database.Query <ArtistEntity>()
                                    select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Artist",
                        a.Name,
                        Lonely    = a.Lonely(),
                        LastAward = a.LastAward
                    })
                              .ToDQueryable(description)
                              .AllQueryOperationsAsync(request, cancellationToken);

                    var two = await(from a in Database.Query <BandEntity>()
                                    select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Band",
                        a.Name,
                        Lonely    = a.Lonely(),
                        LastAward = a.LastAward
                    })
                              .ToDQueryable(description)
                              .AllQueryOperationsAsync(request, cancellationToken);

                    return(one.Concat(two).OrderBy(request.Orders).TryPaginate(request.Pagination));
                })
                                            .Column(a => a.LastAward, cl => cl.Implementations = Implementations.ByAll)
                                            .ColumnProperyRoutes(a => a.Id, PropertyRoute.Construct((ArtistEntity a) => a.Id), PropertyRoute.Construct((BandEntity a) => a.Id)),
                                            entityImplementations: Implementations.By(typeof(ArtistEntity), typeof(BandEntity)));

                Validator.PropertyValidator((NoteWithDateEntity n) => n.Text)
                .IsApplicableValidator <NotNullValidatorAttribute>(n => Corruption.Strict);
            }
        }
Esempio n. 3
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                if (!Schema.Current.Settings.TypeValues.ContainsKey(typeof(TimeSpan)))
                {
                    sb.Settings.FieldAttributes((AlbumEntity a) => a.Songs[0].Duration).Add(new Signum.Entities.IgnoreAttribute());
                    sb.Settings.FieldAttributes((AlbumEntity a) => a.BonusTrack.Duration).Add(new Signum.Entities.IgnoreAttribute());
                }

                sb.Include <AlbumEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.Author,
                    a.Label,
                    a.Year
                });

                sb.Include <NoteWithDateEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Text,
                    a.Target,
                    a.CreationTime,
                });

                sb.Include <PersonalAwardEntity>();
                sb.Include <AwardNominationEntity>();
                sb.Include <ConfigEntity>();

                MinimumExtensions.IncludeFunction(sb.Schema.Assets);
                sb.Include <ArtistEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.IsMale,
                    a.Sex,
                    a.Dead,
                    a.LastAward,
                });

                dqm.RegisterExpression((IAuthorEntity au) => Database.Query <AlbumEntity>().Where(a => a.Author == au), () => typeof(AlbumEntity).NicePluralName(), "Albums");

                sb.Include <BandEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.LastAward,
                });

                sb.Include <LabelEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                });

                sb.Include <AmericanMusicAwardEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Year,
                    a.Category,
                    a.Result,
                });

                sb.Include <GrammyAwardEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Year,
                    a.Category,
                    a.Result
                });

                sb.Include <PersonalAwardEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Year,
                    a.Category,
                    a.Result
                });

                sb.Include <AwardNominationEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Award,
                    a.Author
                });

                dqm.RegisterQuery(typeof(IAuthorEntity), () => DynamicQueryCore.Manual((request, descriptions) =>
                {
                    var one = (from a in Database.Query <ArtistEntity>()
                               select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Artist",
                        a.Name,
                        Lonely = a.Lonely(),
                        LastAward = a.LastAward
                    }).ToDQueryable(descriptions).AllQueryOperations(request);

                    var two = (from a in Database.Query <BandEntity>()
                               select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Band",
                        a.Name,
                        Lonely = a.Lonely(),
                        LastAward = a.LastAward
                    }).ToDQueryable(descriptions).AllQueryOperations(request);

                    return(one.Concat(two).OrderBy(request.Orders).TryPaginate(request.Pagination));
                })
                                  .Column(a => a.LastAward, cl => cl.Implementations = Implementations.ByAll)
                                  .ColumnProperyRoutes(a => a.Id, PropertyRoute.Construct((ArtistEntity a) => a.Id), PropertyRoute.Construct((BandEntity a) => a.Id)),
                                  entityImplementations: Implementations.By(typeof(ArtistEntity), typeof(BandEntity)));

                Validator.PropertyValidator((NoteWithDateEntity n) => n.Text)
                .IsApplicableValidator <StringLengthValidatorAttribute>(n => Corruption.Strict);

                AlbumGraph.Register();

                RegisterOperations();
            }
        }