CodeSmith Community
Your Code. Your Way. Faster!

Improved load and tracking behaviour as per request

Latest post 12-11-2006 8:38 PM by mike123. 1 replies.
  • 12-11-2006 7:52 AM

    • mwerner
    • Top 50 Contributor
    • Joined on 03-02-2006
    • Sweden
    • Posts 106
    • Points 2,376

    Improved load and tracking behaviour as per request

    Here is a patch for this request http://community.codesmithtools.com/forums/permalink/17287/19789/ShowThread.aspx#19789.

    The patch is for svn version 447.

    It contains the following changes.

    1. A bug fix for EntityDataSourceFilter. public String Sort was marked with [Bindable] instead of [Bindable(true)].
    2. DataRepository.Provider has a new public property CurrentLoadPolicy that can take two values either LoadPolicy.PreserveChanges or LoadPolicy.DiscardChanges. The default value is to discard changes in order to mimic the current behavior as closely as possible. However, I find it far more likely that you would want to change the setting to PreserveChanges instead.
    3. EntityManager now has a property public static bool TrackChangedEntities. When set to true netTiers will not stop tracking an entity even if it is modified. It will be tracked until it is saved. This is necessary if you want to control the way Load works. True is the default setting if you for some reason would like to turn tracking of changed entities off then set it to false.

    It is possible to control the values of CurrentLoadPolicy using the app.config file like so

    <add name="SqlNetTiersProvider"
            type="Northwind.Data.SqlClient.SqlNetTiersProvider, Northwind.Data.SqlClient"
            connectionStringName="netTiersConnectionString"
            useStoredProcedure="false"
            providerInvariantName="System.Data.SqlClient"
            entityFactoryType="Northwind.Entities.EntityFactory"
            useEntityFactory="true"
            enableEntityTracking="true"
            enableMethodAuthorization="false"
            defaultCommandTimeout="30"
            currentLoadPolicy="PreserveChanges"/>

    Note! Unless enableEntityTracking is set to true currentLoadPolicy and trackChangedEntities don't have a meaning. It is only when entity tracking is used that they actually affect the behavior of netTiers.

    Beware that this patch do change the way netTiers work with respect to reading entities from the database. Previously if you used entity tracking and "reloaded" entities from the database only new (in the database) and modified entities would get updated with new values from the database (i.e. you would loose unsaved changes). I just could not image why anyone would want that behavior so now when doing the reload you will get the following behavior when using entity tracking;

    1. If currentLoadPolicy="PreserveChanges" and trackChangedEntities = true modified entities will not be updated with value from the database. New entities will be created and unchanged entities will get refreshed with new values from the database.
    2. If currentLoadPolicy="DiscardChanges" and trackChangedEntities = true both changed and unchanged entities will be refreshed with values from the database. You will loose any unsaved changes. New entities in the database will be loaded.
    3. Setting trackChangedEntities = false will when you do a Load give you a similar behavior as if currentLoadPolicy="DiscardChanges”. However the need to do this should be very rare indeed.

     

    Lastly, note that entities are tracked using the primary key when loaded, i.e. if you change the primary key in memory and it has not changed in the database, you will when you load get the modified object instance back from the EntityManager.

    There is room for improvements when it comes to entity tracking, for example, I believe that entities should continue being tracked event when saved. But this is a descent start. If you have ideas let me know. If you don’t like it let me know why. Should you happen to like it please let me know J.

     

    I'll keep an eye on the lists in case you find any bugs, should this make it into the official code base.

    Best regards, Magnus Werner
    • Post Points: 35
  • 12-11-2006 8:38 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 734
    • Points 17,040

    Re: Improved load and tracking behaviour as per request

    Thank you!

    Posted rev. 450

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems