Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jonas 123 posts 206 karma points
    Feb 15, 2016 @ 14:08
    Jonas
    0

    Problems mapping two models to same table.

    Since I want one view to only list activities from today I am creating a new view. But it is not working.

    Is it a limitation of MVC or UI o Matic ?

  • Comment author was deleted

    Feb 16, 2016 @ 11:35

    Must say I haven't given that a shot but will give it a try now

  • Comment author was deleted

    Feb 16, 2016 @ 11:57

    It does work mapping 2 pocos to the same table but in the event model there isn't an option to check for the type only the table, so I've made the necessary changes (building now) will also add some docs here on how to use

  • Comment author was deleted

    Feb 16, 2016 @ 12:16

    Ok verison 1.6.2 is out that allows you to do the following, say we have these 2 classes (that map to the same table)

    [UIOMatic("TestWithDate", "icon-users", "icon-user", RenderType = UIOMaticRenderType.List,
        SortColumn = "TheDate", SortOrder = "desc")]
    [TableName("TestWithDate")]
    public class TestWithDate : IUIOMaticModel
    {
        public TestWithDate()
        {
    
        }
    
    
        [UIOMaticIgnoreField]
        [PrimaryKeyColumn(AutoIncrement = true)]
        public int Id { get; set; }
    
        [UIOMaticField("Firstname", "Enter your firstname")]
        public string FirstName { get; set; }
    
        [UIOMaticField("Lastname", "Enter your lastname")]
        public string LastName { get; set; }
    
        [UIOMaticField("TheDate", "Select a date")]
        public DateTime TheDate { get; set; }
    
        public IEnumerable<Exception> Validate()
        {
    
            return new List<Exception>();
        }
    }
    

    and

    [UIOMatic("TestWithDateLimit", "icon-users", "icon-user", RenderType = UIOMaticRenderType.List,
        SortColumn = "TheDate", SortOrder = "desc")]
    [TableName("TestWithDate")]
    public class TestWithDateLimit : IUIOMaticModel
    {
        public TestWithDateLimit()
        {
    
        }
    
    
        [UIOMaticIgnoreField]
        [PrimaryKeyColumn(AutoIncrement = true)]
        public int Id { get; set; }
    
        [UIOMaticField("Firstname", "Enter your firstname")]
        public string FirstName { get; set; }
    
        [UIOMaticField("Lastname", "Enter your lastname")]
        public string LastName { get; set; }
    
        [UIOMaticField("TheDate", "Select a date")]
        public DateTime TheDate { get; set; }
    
        public IEnumerable<Exception> Validate()
        {
    
            return new List<Exception>();
        }
    }
    

    You can see that both have the same table in the tablename attribute

    Now the changes I've made are to the event model so you can do the following

    First attach to the event

    UIOMatic.Controllers.PetaPocoObjectController.BuildingQuery += PetaPocoObjectController_BuildingQuery1;
    

    then check for the type of object instead of checking for the tablename

        private void PetaPocoObjectController_BuildingQuery1(object sender, UIOMatic.QueryEventArgs e)
        {
    
            if (e.CurrentType == typeof(TestWithDateLimit))
            {
                e.Query.Where("TheDate >= @0", DateTime.Now.AddDays(-1));
    
            }
        }
    

    You'll need to be running the latest version in order to get the CurrentType property on the QueryEventArgs

    Let me know if you have further questions.

    Cheers, Tim

Please Sign in or register to post replies

Write your reply to:

Draft