Beispiel #1
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Settings.AssertImplementedBy((OrderEntity o) => o.Customer, typeof(CompanyEntity));
                sb.Settings.AssertImplementedBy((OrderEntity o) => o.Customer, typeof(PersonEntity));

                sb.Include <PersonEntity>();
                sb.Include <CompanyEntity>();

                dqm.RegisterQuery(typeof(PersonEntity), () =>
                                  from r in Database.Query <PersonEntity>()
                                  select new
                {
                    Entity = r,
                    r.Id,
                    r.FirstName,
                    r.LastName,
                    r.DateOfBirth,
                    r.Phone,
                    r.Fax,
                    r.Address,
                });

                dqm.RegisterQuery(typeof(CompanyEntity), () =>
                                  from r in Database.Query <CompanyEntity>()
                                  select new
                {
                    Entity = r,
                    r.Id,
                    r.CompanyName,
                    r.ContactName,
                    r.ContactTitle,
                    r.Phone,
                    r.Fax,
                    r.Address,
                });

                new Graph <CustomerEntity> .Execute(CustomerOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => { }
                }

                .Register();

                new Graph <CompanyEntity> .Execute(CustomerOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => { }
                }

                .RegisterReplace();

                new Graph <PersonEntity> .Execute(CustomerOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => { }
                }

                .RegisterReplace();

                dqm.RegisterQuery(typeof(CustomerEntity), () => DynamicQuery.Manual((QueryRequest request, QueryDescription descriptions) =>
                {
                    var persons = Database.Query <PersonEntity>().Select(p => new
                    {
                        Entity = p.ToLite <CustomerEntity>(),
                        Id     = "P " + p.Id,
                        Name   = p.FirstName + " " + p.LastName,
                        p.Address,
                        p.Phone,
                        p.Fax
                    }).ToDQueryable(descriptions).AllQueryOperations(request);

                    var companies = Database.Query <CompanyEntity>().Select(p => new
                    {
                        Entity = p.ToLite <CustomerEntity>(),
                        Id     = "C " + p.Id,
                        Name   = p.CompanyName,
                        p.Address,
                        p.Phone,
                        p.Fax
                    }).ToDQueryable(descriptions).AllQueryOperations(request);

                    return(persons.Concat(companies)
                           .OrderBy(request.Orders)
                           .TryPaginate(request.Pagination));
                })
                                  .ColumnProperyRoutes(a => a.Id,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Id),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.Id))
                                  .ColumnProperyRoutes(a => a.Name,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.FirstName),
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.LastName),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.CompanyName))
                                  .ColumnProperyRoutes(a => a.Address,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Address),
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Address))
                                  .ColumnProperyRoutes(a => a.Phone,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Phone),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.Phone))
                                  .ColumnProperyRoutes(a => a.Fax,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Fax),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.Fax))
                                  , entityImplementations: Implementations.By(typeof(PersonEntity), typeof(CompanyEntity)));

                dqm.RegisterExpression((CustomerEntity c) => c.Address).ForcePropertyRoute = PropertyRoute.Construct((PersonEntity p) => p.Address);
                dqm.RegisterExpression((CustomerEntity c) => c.Phone).ForcePropertyRoute   = PropertyRoute.Construct((PersonEntity p) => p.Address);
                dqm.RegisterExpression((CustomerEntity c) => c.Fax).ForcePropertyRoute     = PropertyRoute.Construct((PersonEntity p) => p.Address);
            }
        }
Beispiel #2
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>();
                sb.Include <NoteWithDateEntity>();
                sb.Include <PersonalAwardEntity>();
                sb.Include <AwardNominationEntity>();
                sb.Include <ConfigEntity>();

                MinimumExtensions.IncludeFunction(sb.Schema.Assets);

                dqm.RegisterQuery(typeof(AlbumEntity), () =>
                                  from a in Database.Query <AlbumEntity>()
                                  select new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.Author,
                    a.Label,
                    a.Year
                });

                dqm.RegisterQuery(typeof(NoteWithDateEntity), () =>
                                  from a in Database.Query <NoteWithDateEntity>()
                                  select new
                {
                    Entity = a,
                    a.Id,
                    a.Text,
                    a.Target,
                    a.CreationTime,
                });

                dqm.RegisterQuery(typeof(ArtistEntity), () =>
                                  from a in Database.Query <ArtistEntity>()
                                  select 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");

                dqm.RegisterQuery(typeof(BandEntity), () =>
                                  from a in Database.Query <BandEntity>()
                                  select new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.LastAward,
                });


                dqm.RegisterQuery(typeof(LabelEntity), () =>
                                  from a in Database.Query <LabelEntity>()
                                  select new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                });


                dqm.RegisterQuery(typeof(AmericanMusicAwardEntity), () =>
                                  from a in Database.Query <AmericanMusicAwardEntity>()
                                  select new
                {
                    Entity = a,
                    a.Id,
                    a.Year,
                    a.Category,
                    a.Result,
                });

                dqm.RegisterQuery(typeof(GrammyAwardEntity), () =>
                                  from a in Database.Query <GrammyAwardEntity>()
                                  select new
                {
                    Entity = a,
                    a.Id,
                    a.Year,
                    a.Category,
                    a.Result
                });

                dqm.RegisterQuery(typeof(PersonalAwardEntity), () =>
                                  from a in Database.Query <PersonalAwardEntity>()
                                  select new
                {
                    Entity = a,
                    a.Id,
                    a.Year,
                    a.Category,
                    a.Result
                });

                dqm.RegisterQuery(typeof(AwardNominationEntity), () =>
                                  from a in Database.Query <AwardNominationEntity>()
                                  select new
                {
                    Entity = a,
                    a.Id,
                    a.Award,
                    a.Author
                });


                dqm.RegisterQuery(typeof(IAuthorEntity), () => DynamicQuery.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();
            }
        }