Business logic / extend

6 posts, 0 answers
  1. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 14 Jul 2011 Link to this post

    Hi,

    maybe a double post, but regarding Open Access I'm always asking myself if I'm reading a post or a blog on the old or the new way... the doc and blogs are not dated so that makes it that much harder...

    I'm having some general questions regarding Open Access, latest version Q2 2011. I'll post them separately.

    Q: The idea behind a model is that you can sperate your business logic into sperate files, partial classes, and extent an entity. I common problem with this is that the entity does not know to what connection, and therefore database, it belongs.

    for example: In my entity I to check or update other data, but there is no connection instance there of the context.

    what do you advise?

    Erik
  2. Serge
    Admin
    Serge avatar
    375 posts

    Posted 15 Jul 2011 Link to this post

    Hi Erik,

     Unfortunately there is no way (at the moment) to know about the context that is responsible for an entity, however given that the context is something you are handling it is quite possible that this is something you have access to from everywhere. 

     Previously that could be handled by the Tracking API that would give out a couple of methods that you can implement in a class, however at this time we have not introduced that in the context based api (the visual designer). 

    What you can do however is to create an interface that has an update method that takes a hold of a context and implement that interface in partial classes for all of your entities. Just implement that method and whenever you are saving changes you can use the GetChanges API of the context to retrieve all changed objects and then call their update method.

    You can even refactor this in an extension method for the context, or in a partial class. Do ask if you want a code sample.

    I hope this sheds some more light on the situation. Do not hesitate to ask if there is something left that is unclear. 

    Kind regards,
    Serge
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. DevCraft banner
  4. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 19 Jul 2011 Link to this post

    Hi Serge,

    I'm already using the Tracking API. the only thing missing I would say is a "create" event in the Tracking. there is a Refresh event, I've never seen that fire, but the others do well, an allow me to keep track of changes users are making and even what user en when is logged. also all my entities inherit from a base entity class, where I handle PropertyChange and the tracking events subs are in there. so the model raises the "update" sub in the entity on saving (update trigger from the tracking) and passes on itself. Extended entities can therefore react on update/new/delete.

    Is there a performance penalty using Tracking, aside from what I'm doing in the event of course.

    Is there no way to tell the model that all entities must inherit from a base entity? I'm doing it in my code generation template file now...

    Regards,

    Erik
  5. Serge
    Admin
    Serge avatar
    375 posts

    Posted 20 Jul 2011 Link to this post

    Hi Erik,

     We do provide support for inheritance in the designer but I don't think that this is what you are trying to do. There is little or no penalty to the Tracking API as it is just calling a couple of methods that you are providing. And if you are talking about providing a way to make all classes inherit from a class that is not in the diagram we have no plans for such a feature right now.

    Let's make sure I understand you correctly, do you need to track the creation of object rather than adding them to the context? 

    I am looking forward to resolving this matter with you. 

    Greetings,
    Serge
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 23 Jul 2011 Link to this post

    Hi Serge,

    No, I think adding to context is enough, creation of the object is mostly something you do yourself, so...
    Can I do/see that already with the current model context?

    Erik
  7. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 27 Jul 2011 Link to this post

    Hello Erik,

    Since you are already familiar with the tracking API, I think the Adding/Added events are what you are looking for. You can access the tracking object from the inner object scope of the context and subscribe to the needed events. To do this you will have to create a partial class with the name of your context (EntitiesModel in the example) and include the following code:

    public partial class EntitiesModel
    {
        public ITracking Tracking
        {
            get
            {
                return this.GetScope().Tracking;
            }
        }
    }
     
    class Program
    {
        static void Main(string[] args)
        {
            using (EntitiesModel context = new EntitiesModel())
            {
                context.Tracking.Added += new AddEventHandler(Tracking_Added);
     
                context.Add(new Table1());
                context.SaveChanges();
            }
        }
     
        static void Tracking_Added(object sender, AddEventArgs e)
        {
                 
        }
    }

    I hope that helps.

    Best wishes,
    Alexander
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top
DevCraft banner