CodeSmith Community
Your Code. Your Way. Faster!

EntityTrackingKey issue

Latest post 11-10-2006 10:12 AM by GRAW. 3 replies.
  • 11-02-2006 2:42 PM

    • GRAW
    • Top 25 Contributor
    • Joined on 06-23-2006
    • Posts 157
    • Points 4,560

    EntityTrackingKey issue

    I have a few entities in my project which have a composite primary key and when the tracking key for these entities is generated there will be an overlap between the keys.

    I have an Order entity and an OrderLine entity, PK on OrderLIne is orderId, lineNumber.  When creating a tracking key for the OrderLine entity it comes out to something like this: "OrderLine3581", given an orderId of 385 and lineNumber 1.  Needless to say there are a lot of issues with this key, once a variety of entities will populate the database we'll get the wrong entity from the cache.  I have made some changes to the template to use EntityLocator.ConstructKeyFromPkItems() whenever it needs to create keys, and in that method I have this:

                for (int i = 0; i < pkItems.Length; i++)
                {
                    if (pkItemsIdea != null)
                        sb.Append('|').Append(pkItemsIdea.ToString());
                }

    I think this should be integrated into the release, as it is quite a gap for composite keys. 

    "Small is the number of them that see with their own eyes, and feel with their own hearts" Albert Einstein
    • Post Points: 35
  • 11-07-2006 3:51 PM In reply to

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

    Re: EntityTrackingKey issue

    I'd second that. Make a patch and post it under contributions. I think the netTiers team would love to incorporate that.
    Best regards, Magnus Werner
    • Post Points: 35
  • 11-10-2006 10:08 AM In reply to

    Re: EntityTrackingKey issue

    This has been done and will be posted soon.

    It looks like this for both EntityInstance and DataProvider:

        if(entityTrackingKey == null)
         entityTrackingKey = string.Format(@"<%= className %>{0}{1}{0}{2}{0}{3}{0}{4}", "|" <%
        for (int x=0; x < cols.Count;x++) {
         if(cols[x].IsPrimaryKeyMember) {%>
         , this.<%=GetPropertyName(cols[x].Name)%>.ToString()<%
         }// end if
        } //end for each column %>);


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 11-10-2006 10:12 AM In reply to

    • GRAW
    • Top 25 Contributor
    • Joined on 06-23-2006
    • Posts 157
    • Points 4,560

    Re: EntityTrackingKey issue

    Thank you Robert.
    "Small is the number of them that see with their own eyes, and feel with their own hearts" Albert Einstein
    • Post Points: 5
Page 1 of 1 (4 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems