<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Auditing Inserts with Identity columns</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Auditing Inserts with Identity columns</description>
  <pubDate>Tue, 14 Apr 2026 10:14:59 -700</pubDate>
  <lastBuildDate>Tue, 19 Mar 2013 09:29:35 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=2717</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Auditing Inserts with Identity columns : Agree, but I prefer to record...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16055#16055</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1264" rel="nofollow">katit</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 19-Mar-2013 at 9:29am<br /><br />Agree, but I prefer to record user names and keep it "loose" in specific places - like Audit table. I really don't like an idea of keeping user name in each table. I think this is bad design.]]>
   </description>
   <pubDate>Tue, 19 Mar 2013 09:29:35 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16055#16055</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns : Unless you never plan to delete...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16054#16054</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1570" rel="nofollow">KitKat</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 19-Mar-2013 at 6:31am<br /><br />Unless you never plan to delete users, having an actual FK relationship is bad, as no matter what table its in, you now either cannot delete users, or have incomplete history. &nbsp;I simply record the username and link at&nbsp;run-time&nbsp;based on that. &nbsp;That way I can delete users and still maintain 100% complete Audit Logging&nbsp;which&nbsp;is very important for the financial applications we write.<div><br></div><div>-Katerina</div>]]>
   </description>
   <pubDate>Tue, 19 Mar 2013 06:31:16 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16054#16054</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns : I just looked at what I do again...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16052#16052</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1264" rel="nofollow">katit</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 18-Mar-2013 at 6:38pm<br /><br />I just looked at what I do again and remember why this feature important to us. Putting CreatedOn timestamp on table is OK, but CreatedBy which FK's to user table is kind of overkill. I started designing this way but when you have hundreds of tables and all of them reference User table it becomes ugly. I'd rather keep it in separate table.<br /><br />With current model I can catch updates and audit that but no luck with "creates"]]>
   </description>
   <pubDate>Mon, 18 Mar 2013 18:38:24 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16052#16052</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns : Hi Marcel,In most cases, we do...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16030#16030</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 15-Mar-2013 at 9:32am<br /><br />Hi Marcel,<div><br></div><div>In most cases, we do what you suggest and it works fine for us. &nbsp;Talking about the joy of legacy systems, we actually don't have any 'real' FKs in our databases. &nbsp;The&nbsp;Referential&nbsp;Integrity gets enforced by triggers. &nbsp;So even for basic things like Order &lt;-- --&gt; Order Detail, we need to manually add Navigation Properties / Associations so that DevForce/EF knows the two entities are related.</div><div><br></div><div>There is one major caveat to that approach for us though. &nbsp;If Entity Framework doesn't think there is a FK in the database, it won't worry about trying to perform INSERT/UPDATE/DELETEs in any particular order. &nbsp;So in the case of something like Order and OrderDetail, Entity Framework might decide to add the OrderDetail row ahead of the Order row. &nbsp;But since we do have triggers enforcing relationships, that will break since obviously an OrderDetail without an Order is not valid.</div><div><br></div><div>The cases where I need the recursive save behavior is not in these simple cases. &nbsp;It's in more complicated scenarios like the one I gave where I need to use the auto-generated primary key values to build up a string. &nbsp;In that case, there isn't really a way I can make an association to express that. &nbsp;And in the case of locking, it would get very annoying to have 400&nbsp;associations coming out of our lock table - our entity model is already hard enough to read! :-)</div><div><br></div><div>Thanks for the suggestions,</div><div><br></div><div>-Stephen</div>]]>
   </description>
   <pubDate>Fri, 15 Mar 2013 09:32:08 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16030#16030</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns : Katerina,I&amp;#039;m glad I was able...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16029#16029</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 15-Mar-2013 at 9:21am<br /><br /><span style=": rgb251, 251, 253;">Katerina,</span><div><span style=": rgb251, 251, 253;"><br></span></div><div><span style=": rgb251, 251, 253;">I'm glad I was able to explain my use cases. &nbsp;I do agree that some of what I'm doing is because of a legacy system we are forced to work with. &nbsp;But even if I had the power to completely restructure our tables in whatever way I wanted, it still seems a bit extreme to say that I need to go with some sort of TablePerHierarchy structure and change hundreds of tables just because it ends up with better C# code to implement a simple change like adding locking. &nbsp;I'm all for solid design, but it's not an exact science and there always has to be trade-offs and&nbsp;compromises. &nbsp;</span></div><div><span style=": rgb251, 251, 253;"><br></span></div><div><span style=": rgb251, 251, 253;">And yes, I'm very willing to hear alternate suggestions. &nbsp;I see Marcel has offered some which I'll respond to in a&nbsp;separate&nbsp;post.</span></div><div><span style=": rgb251, 251, 253;"><br></span></div><div><span style=": rgb251, 251, 253;">One last thing to mention.....you've said that a save within a save sounds weird. &nbsp;But that is exactly the kind of thing that makes Entity Framework so amazing. &nbsp;I can make a single call to "Save" and Entity Framework will end up&nbsp;issuing&nbsp;a bunch of INSERT/UPDATE/DELETEs on my behalf. &nbsp;The power that EF has when it comes to ordering the individual saves, coordinating things when there are relationships, and performing in a single transaction are part of what makes EF so powerful. &nbsp;So even a 'vanilla' SaveChanges call with DevForce ends up triggering multiple individual saves from within the bigger umbrellas Save. &nbsp;In my case, I'm just trying to extend the behavior a bit to include some additional saves apart from what EF does to take care of the cases where EF can't figure it out on its own. &nbsp;Of course, maybe you'll disagree with this....and it is a bit borderline whether this is really a save within a save....but just thought I'd mention it.</span></div><div><span style=": rgb251, 251, 253;"><br></span></div><div><span style=": rgb251, 251, 253;">Thanks for the lively discourse!</span></div><div><span style=": rgb251, 251, 253;"><br></span></div><div><span style=": rgb251, 251, 253;">-Stephen</span></div>]]>
   </description>
   <pubDate>Fri, 15 Mar 2013 09:21:11 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16029#16029</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns : Stephen,Perhaps something to consider....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16027#16027</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 15-Mar-2013 at 7:48am<br /><br />Stephen,<div>Perhaps something to consider. Even though you don't have FKs in the database for your audit tables, you can still define navigation properties in your model so DevForce can fix up the keys. If you do that, then you can simply add the audit entities the to the save list in the SaveInterceptor and all gets saved in one transaction.&nbsp;</div><div><br></div><div>The constraints in your model do not have to exactly match the constraints in the database.&nbsp;</div>]]>
   </description>
   <pubDate>Fri, 15 Mar 2013 07:48:07 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16027#16027</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns : I realized that I have not specified...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16026#16026</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1570" rel="nofollow">KitKat</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 15-Mar-2013 at 5:58am<br /><br />I realized that I have not specified before. &nbsp;My examples are in the context of a Code First approach. &nbsp;I just cannot give up the flexibility that it provides.]]>
   </description>
   <pubDate>Fri, 15 Mar 2013 05:58:09 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16026#16026</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns : Good morning Stephan,	I have not...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16025#16025</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1570" rel="nofollow">KitKat</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 15-Mar-2013 at 5:53am<br /><br />Good morning Stephan,<div><span ="Apple-tab-span" style="white-space:pre">	</span>I have not seen either of these use cases before. &nbsp;Thank you for the information into the reasoning. &nbsp;I can almost get behind this feature request now, as I cannot outright come up with a good clean answer to these. &nbsp;</div><div><br></div><div><span ="Apple-tab-span" style="white-space:pre">	</span>I do see however that these issues are both created by previous design not following some of the pricipal best practices that DevForce is based upon. &nbsp;</div><div><br></div><div><span ="Apple-tab-span" style="white-space:pre">	</span>While writing this, I did have one idea. &nbsp;It would be nice if we could create a TablePerHierarchy structure where each derived time implemented the same column. &nbsp;Obviously SQL would not be able to enforce the foreign keys, but maybe DevForce could? &nbsp;I will have to test this, maybe even write up my own feature request.</div><div><br></div><div><span ="Apple-tab-span" style="white-space:pre">	</span>I am sure you have thought about this much more than I and you use case hear seems sound. &nbsp;I do think that this evidence supports the review of this feature request. &nbsp;Maybe a better way will come form the developers or maybe they will ad this. &nbsp;A save within a save still just seems wrong to me, but hey, there have been things that seemed wrong that were required to get software out all the time too.</div><div><br></div><div>Thank you,</div><div>Katerina</div>]]>
   </description>
   <pubDate>Fri, 15 Mar 2013 05:53:38 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16025#16025</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns : Sorry to take over this thread...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16021#16021</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=613" rel="nofollow">stephenmcd1</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 14-Mar-2013 at 5:58pm<br /><br />Sorry to take over this thread with my feature request....but the forums have a much richer editor so it's easier to compose a large response here rather than on User Voice.<div><p ="Ms&#111;normal">Hi Katerina, thanks for the thorough response.&nbsp; I'll try to comment on why I think this is,in fact, a very useful and architecturally sound feature request.<o:p></o:p></p><p ="Ms&#111;normal">As for auditing/logging, I agree with much of what yousay.&nbsp; An 'AuditEntityBase' base classseems like a wonderful idea.&nbsp; However, weare dealing with a legacy database as well as other client applications that we need topeacefully coexist with.&nbsp; So adding 2extra columns to hundreds of tables is not something that would really go overwell.&nbsp; Side note: we do have aninterface that contains ModifiedDate and ModifiedUser and do use that in the same way you suggest - but we are only able to do this because those fields already existed in our database so it was an easy one for us to'do right'.&nbsp;&nbsp;Unfortunately, sometimes a legacy systemforces you to do things that&nbsp;aren't&nbsp;how you would do it on a brand new project<o:p></o:p></p><p ="Ms&#111;normal">I've already digressed a bit because, as it turns out, our application uses database triggers formost of our auditing and logging.&nbsp; It'svery straightforward logic that I have no problems doing in a trigger with abunch of boilerplate and unchanging SQL.&nbsp; There's not a lot ofcomplicated business logic and, as a bonus, all our client applications get thatauditing/logging behavior 'for free' without having to 'reinvent the wheel'.&nbsp; Also, updates to our database through'not-so-official-methods' (e.g. ad-hoc SQL scripts) end up triggering the sameaudit/logging logic so there is no way to bypass it.<o:p></o:p></p><p ="Ms&#111;normal">As you might have guessed, I'm not requesting this feature in orderto perform logging or auditing.&nbsp; Nearlyall of my use cases involve times where I need to know the auto-generatedprimary key of an entity and use it to update the database in the sametransaction as the original save.&nbsp; The specific cases are abit domain-specific, but I’ll try to give some simplified examples.&nbsp; Imagine this kind of scenario:<o:p></o:p></p><p ="Ms&#111;normal">Imagine we have a table that contains 'email deliveryrequests'.&nbsp; The table functions as aqueue where our application can add requests and some other system picks upthose requests and services them by sending emails.&nbsp; So maybe after a new Customer is saved, wewant add a new entity such as the following: new EmailDeliveryRequest{Subject="NewCustomer Created", To="Bob", Body="There is a new customer with ID 123 that youshould do something with"}.&nbsp; How would we do this with DevForce...let's look at the existing options:</p><p ="Ms&#111;normal"><ol><li><span style="line-height: 1.4;">We add the new EmailDeliveryRequest entity before the save because we don’t knowwhat the customer's ID will be.</span><span style="line-height: 1.4;">&nbsp;&nbsp;</span></li><li><span style="line-height: 1.4;">This&nbsp;</span>isn't<span style="line-height: 1.4;">&nbsp;the kind of thing that we'd want to put in a trigger because the logic can getcomplicated (some new customers go to Bob, other ones go to Sally, etc.). &nbsp;And I very much dislike having non-trivial logic hidden away in SQL where I can't see it, test it, etc.</span></li><li><span style="line-height: 1.4;">We most certainly want the request to becreated within the same transaction so we don’t have to worry about a Customergetting saved correctly but then something going wrong when we try to save theEmailDeliveryRequest. &nbsp;So trying to make two SaveChanges calls from the client is not an option.</span></li><li><span style="line-height: 1.4;">We can't just make an association in our model and have the temporary-id fixup logic take care of it since the ID ends up stuffed in a string so DevForce/EF would have no chance at figuring it out.</span></li><li><span style="line-height: 1.4;">Write a stored procedure where we pass Subject/To/Body and it adds a row for us. &nbsp;Then we can call this procedure as part of the save process within the transaction. &nbsp;This ends up being the only viable solution so we go with it. &nbsp;But then we have a bunch of stored procedures that exist solely to do something&nbsp;</span>embarrassingly<span style="line-height: 1.4;">&nbsp;simple like add 3 values to a table somewhere. &nbsp;Not very fun. &nbsp;A related solution would be to drop down to low-level ADO.NET, raw SQL or something like that to do the INSERTs. &nbsp;Again, not a very fun thing to do.</span></li></ol><div>I'll give another example because I just ran across it in our code. &nbsp;We have the option of using&nbsp;pessimistic&nbsp;locking in our application (for customers that want to use it, that is - I'll happily admit that I'm not a big fan of the feature). &nbsp;So we have a table in our database that holds all the items that are locked. &nbsp;When a new item is saved for the first time, we want to immediately add a row in that table so that we have the item locked (it would be weird for the user to find out that the brand new item that they just saved for the first time is getting forced to read-only because somebody else grabbed a lock on it right after it got saved - which is not that uncommon, in fact, because we have a lot of background tasks that are looking for newly saved items). &nbsp;In this case, we have pretty much the same limitations as before. &nbsp;We need to know the primary key, it's not something I'd want in a trigger, we need it to be in the same transaction to avoid a confusing user experience, making associations in the model are non-trivial since the lock table has columns like "item_type" and "item_id" - DevForce/EF have a hard time understanding that item_id could refer to any possible entity type in our system (which number in the hundreds). &nbsp;As it turns out, we ended up going with a stored procedure in this case as well - even though it might have been nice to just be able to insert a row in that table using a few lines of C# code if we could call SaveChanges.</div><div><br></div><div>Hopefully I've explained my use cases. &nbsp;I'm obviously&nbsp;biased, but I think these are&nbsp;legitimate&nbsp;business cases that are hard, if not impossible, to solve in a clean way without support for recursive saves.</div><div><br></div><div>Thanks,</div><div>-Stephen</div><o:p></o:p></p></div>]]>
   </description>
   <pubDate>Thu, 14 Mar 2013 17:58:44 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16021#16021</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns :  I am slightly confused here....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16016#16016</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1570" rel="nofollow">KitKat</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 14-Mar-2013 at 1:09pm<br /><br />I am slightly confused here. &nbsp;I ended up hear reading the suggested features on the website that linked to this thread as support. &nbsp;Honestly the idea of saving while saving has always rubbed me the wrong way as there has to be a better way. &nbsp;To point out, I use an AuditEntityBase that derived from my EntityBase and has fields for your normal basic audit, CreateUser, CreateDate, ModifyUser and ModifyDate. &nbsp;This offers some basic metrics to show in the program of the create information as well as the last modified information. &nbsp;I go further in an SaveInterceptor to create auditlog records for any entity that has been Modified or Deleted into a shared audit information table with before/after values, keys, and user/date info. &nbsp;This method also updates any entity deriving from AuditEntityBase with the latest modified information. &nbsp;This is all done BEFORE ExecuteSave so it includes the entire operation in one database operation. &nbsp;<div><br></div><div>"WAIT!, What about the create information for that record." is the answer I normally get from this. &nbsp;But look back and read carefully. &nbsp;EVERY Entity that derives from AuditEntityBase has CreateUser and CreateDate on the record itself. &nbsp;"What about the values?" I then normally get asked. &nbsp;Well the Values are simply the first Before value in any modified auditLog record.</div><div><br></div><div>I know this feature has many votes, but it will not be getting mine, and I hope that without more evidence that this is not added. &nbsp;I cannot think and have not seen presented any reason I would want to perform a second save in the middle of the operation of a first save.</div><div><br></div><div>As a note, I am far from perfect, and if a use case is presented that would warrant such a behavior, I would support such a feature. &nbsp;My post is here to address this one issue and address the feature in general.</div><div><br></div><div>Thank you for your time,</div><div>Katerina</div><span style="font-size:10px"><br /><br />Edited by KitKat - 14-Mar-2013 at 1:10pm</span>]]>
   </description>
   <pubDate>Thu, 14 Mar 2013 13:09:43 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=16016#16016</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns : Same here!   </title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=12699#12699</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1181" rel="nofollow">jradxl</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 19-Feb-2012 at 8:46am<br /><br />Same here!<br><br>]]>
   </description>
   <pubDate>Sun, 19 Feb 2012 08:46:45 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=12699#12699</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns :   Another vote for adding some...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=11862#11862</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1264" rel="nofollow">katit</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 18-Oct-2011 at 5:44pm<br /><br />Another vote for adding some way to retreive identity values for newly inserted entities]]>
   </description>
   <pubDate>Tue, 18 Oct 2011 17:44:13 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=11862#11862</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns :   G&amp;#039;day Silvio,Thanks for...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10925#10925</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1155" rel="nofollow">Wokket</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 09-Jun-2011 at 1:56pm<br /><br />G'day Silvio,<div>&nbsp;</div><div>Thanks for getting back to me on&nbsp; this...&nbsp; I ended up with a variant of your Message Queue approach.&nbsp; We're now creating our audit records client-side as part of our repositories Save method, prior to calling EntityManager.SaveChanges() for updates and deletes, as this avoids the issues with running a custom IPrincipal.</div><div>&nbsp;</div><div>We then create Audit records for the inserted entities, and save them with a second call to SaveChanges().&nbsp; This is obviously non-atomic, and can potentially result in inserted records with no audit information, but that seems unavoidable at this point.</div><div>&nbsp;</div><div>Cheers</div>]]>
   </description>
   <pubDate>Thu, 09 Jun 2011 13:56:08 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10925#10925</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns :   Hi Wokket,Unfortunatelly,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10923#10923</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 09-Jun-2011 at 12:06pm<br /><br />Hi Wokket,<div></div><div>Unfortunatelly, this not possible within IdeaBlade. </div><div>I am adding this to our feature request list.</div><div>&nbsp;</div><div>As for a workaround, I'd suggest doing the auditing via a trigger in the DB.</div><div>Another possibility is using <a href="http://msdn.microsoft.com/en-us/library/system.messaging.messagequeue.aspx" target="_blank">MessageQueue</a>. In this case you'd save (i.e. base.ExecuteSave) and add to the queue with the resolved IDs. Then you'd periodically check the queue and perform the saves on the queued audit entities.</div><div>&nbsp;</div><div>Regards,</div><div>&nbsp;&nbsp; Silvio.</div>]]>
   </description>
   <pubDate>Thu, 09 Jun 2011 12:06:00 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10923#10923</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns :   G&amp;#039;day guys,Any further...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10881#10881</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1155" rel="nofollow">Wokket</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 02-Jun-2011 at 12:07am<br /><br />G'day guys,<div>&nbsp;</div><div>Any further ideas with this?</div><div>&nbsp;</div><div>It's temporarily been placed on hold due to us running into the "random null-ref when getting properties" issue noted in <a href="http://www.ideablade.com/forum/forum_posts.asp?TID=2714&amp;title=strange-null-reference" target="_blank">http://www.ideablade.com/forum/forum_posts.asp?TID=2714&amp;title=strange-null-reference</a>&nbsp;, which stop occurring as soon as we stop using a custom (UserBase derived)&nbsp;Principal and revert to a purely anonymous connection.</div><div>&nbsp;</div><div>I'll be looking to hit it pretty hard early next week, and any further suggestion by then would be very welcome!</div><div>&nbsp;</div><div>Cheers</div>]]>
   </description>
   <pubDate>Thu, 02 Jun 2011 00:07:54 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10881#10881</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns :   Apologies for the poor formatting...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10846#10846</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1155" rel="nofollow">Wokket</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 26-May-2011 at 5:03pm<br /><br />Apologies for the poor formatting of the code above, the forum seems to eat whitespace.]]>
   </description>
   <pubDate>Thu, 26 May 2011 17:03:22 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10846#10846</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns :   G&amp;#039;day Robert,The Audit...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10845#10845</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1155" rel="nofollow">Wokket</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 26-May-2011 at 5:02pm<br /><br />G'day Robert,<div>&nbsp;</div><div>The Audit table is defined as an Entity in our EDMX, but does not have a FKey back to the source table... we have a single audit table for the entire schema, storing the related entity name (GetType().Name) and ID as a non-related int.</div><div>&nbsp;</div><div>Our save interceptor currently looks as follows:</div><div><font face="C&#111;nsolas"><table width="99%"><tr><td><pre class="BBcode"></font><font face="C&#111;nsolas"><font face="C&#111;nsolas"></div></font></font><div><font face="C&#111;nsolas"><font color="#808080" face="C&#111;nsolas"><font color="#808080" face="C&#111;nsolas"><p>///</p></font><p></p></font><p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas"> </font></font><font color="#808080" face="C&#111;nsolas"><font color="#808080" face="C&#111;nsolas">&lt;summary&gt;</font></font></p><font color="#808080" face="C&#111;nsolas"><font color="#808080" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>    </p></font><p><font color="#808080" face="C&#111;nsolas"><font color="#808080" face="C&#111;nsolas">///</font></font><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas"> This class is hooked into the Save pipeline to allow us to audit changes to data.</font></font></p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>    </p></font><p><font color="#808080" face="C&#111;nsolas"><font color="#808080" face="C&#111;nsolas">///</font></font><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas"> </font></font><font color="#808080" face="C&#111;nsolas"><font color="#808080" face="C&#111;nsolas">&lt;/summary&gt;</font></font></p><font color="#808080" face="C&#111;nsolas"><font color="#808080" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>    </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">public</font></font><font face="C&#111;nsolas"> </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">class</font></font><font face="C&#111;nsolas"> </font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">AuditingSaveInterceptor</font></font><font face="C&#111;nsolas"> : </font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">EntityServerSaveInterceptor</font></font></p><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>    {</p><p>        </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">protected</font></font><font face="C&#111;nsolas"> </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">override</font></font><font face="C&#111;nsolas"> </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">bool</font></font><font face="C&#111;nsolas"> ExecuteSave()</font></p><font face="C&#111;nsolas"><p>        {</p><p>            </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">var</font></font><font face="C&#111;nsolas"> entitiesBeingAdded = EntityManager.FindEntities(</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">EntityState</font></font><font face="C&#111;nsolas">.Added).OfType&lt;</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">Entity</font></font><font face="C&#111;nsolas">&gt;().ToList(); </font><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas">//get a concrete list, not a queryable.</font></font></p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>            </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">var</font></font><font face="C&#111;nsolas"> entitiesBeingUpdated = EntityManager.FindEntities(</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">EntityState</font></font><font face="C&#111;nsolas">.Modified).OfType&lt;</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">Entity</font></font><font face="C&#111;nsolas">&gt;().ToList();</font></p><font face="C&#111;nsolas"><p>            AuditUpdates(entitiesBeingUpdated);</p><p>            </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">var</font></font><font face="C&#111;nsolas"> entitiesBeingDeleted = EntityManager.FindEntities(</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">EntityState</font></font><font face="C&#111;nsolas">.Deleted).OfType&lt;</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">Entity</font></font><font face="C&#111;nsolas">&gt;().ToList();</font></p><font face="C&#111;nsolas"><p>            AuditDeletes(entitiesBeingDeleted);</p><p>            </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">if</font></font><font face="C&#111;nsolas"> (!</font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">base</font></font><font face="C&#111;nsolas">.ExecuteSave())</font></p><font face="C&#111;nsolas"><p>            {</p><p>                </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">return</font></font><font face="C&#111;nsolas"> </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">false</font></font><font face="C&#111;nsolas">; </font><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas">//don't go any further if that bit of work failed.</font></font></p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>            }</p><p>            </p></font><p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas">//</font></font><b><font color="#00008b" face="C&#111;nsolas"><font color="#00008b" face="C&#111;nsolas">TODO: Audit inserts later on.  See http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10825#10825</font></font></b></p><b><font color="#00008b" face="C&#111;nsolas"><font color="#00008b" face="C&#111;nsolas"></font></font></b><font color="#00008b" face="C&#111;nsolas"><font color="#00008b" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>            </p></font><p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas">//AuditInserts(entitiesBeingAdded); </font></font></p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>            </p></font><p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas">// return base.ExecuteSave(); //doesn't save the new Added audit records, attempts to re-save the items saved above.\</font></font></p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>            </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">return</font></font><font face="C&#111;nsolas"> </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">true</font></font><font face="C&#111;nsolas">;</font></p><font face="C&#111;nsolas"><p>        }</p><p>        </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">private</font></font><font face="C&#111;nsolas"> </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">void</font></font><font face="C&#111;nsolas"> AuditDeletes(</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">IEnumerable</font></font><font face="C&#111;nsolas">&lt;</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">Entity</font></font><font face="C&#111;nsolas">&gt; entitiesBeingUpdated)</font></p><font face="C&#111;nsolas"><p>        {</p><p>            AuditChanges(entitiesBeingUpdated, </p></font><p><font color="#a31515" face="C&#111;nsolas"><font color="#a31515" face="C&#111;nsolas">"Delete"</font></font><font face="C&#111;nsolas">);</font></p><font face="C&#111;nsolas"><p>        }</p><p>        </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">private</font></font><font face="C&#111;nsolas"> </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">void</font></font><font face="C&#111;nsolas"> AuditUpdates(</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">IEnumerable</font></font><font face="C&#111;nsolas">&lt;</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">Entity</font></font><font face="C&#111;nsolas">&gt; entitiesBeingUpdated)</font></p><font face="C&#111;nsolas"><p>        {</p><p>            AuditChanges(entitiesBeingUpdated, </p></font><p><font color="#a31515" face="C&#111;nsolas"><font color="#a31515" face="C&#111;nsolas">"Edit"</font></font><font face="C&#111;nsolas">);</font></p><font face="C&#111;nsolas"><p>        }</p><p>        </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">private</font></font><font face="C&#111;nsolas"> </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">void</font></font><font face="C&#111;nsolas"> AuditInserts(</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">IEnumerable</font></font><font face="C&#111;nsolas">&lt;</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">Entity</font></font><font face="C&#111;nsolas">&gt; entitiesBeingAdded)</font></p><font face="C&#111;nsolas"><p>        {</p><p>            AuditChanges(entitiesBeingAdded, </p></font><p><font color="#a31515" face="C&#111;nsolas"><font color="#a31515" face="C&#111;nsolas">"Add"</font></font><font face="C&#111;nsolas">);</font></p><font face="C&#111;nsolas"><p>        }</p><p>        </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">private</font></font><font face="C&#111;nsolas"> </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">void</font></font><font face="C&#111;nsolas"> AuditChanges(</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">IEnumerable</font></font><font face="C&#111;nsolas">&lt;</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">Entity</font></font><font face="C&#111;nsolas">&gt; entitiesBeingUpdated, </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">string</font></font><font face="C&#111;nsolas"> auditType)</font></p><font face="C&#111;nsolas"><p>        {</p><p>            </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">if</font></font><font face="C&#111;nsolas"> (Principal == </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">null</font></font><font face="C&#111;nsolas"> || Principal.Identity.AuthenticationType == </font><font color="#a31515" face="C&#111;nsolas"><font color="#a31515" face="C&#111;nsolas">"Anonymous"</font></font><font face="C&#111;nsolas">)</font></p><font face="C&#111;nsolas"><p>            {</p><p>                </p></font><p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas">// we can't audit this without a proper ID to record it against</font></font></p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>                </p></font><p><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">Debug</font></font><font face="C&#111;nsolas">.Assert(</font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">false</font></font><font face="C&#111;nsolas">, </font><font color="#a31515" face="C&#111;nsolas"><font color="#a31515" face="C&#111;nsolas">"DANGER: Not recording audit information as there's no authentication information available."</font></font><font face="C&#111;nsolas">);</font></p><font face="C&#111;nsolas"><p>                </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">return</font></font><font face="C&#111;nsolas">;</font></p><font face="C&#111;nsolas"><p>            }</p><p>            </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">var</font></font><font face="C&#111;nsolas"> userId = ((</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">HCareIdentity</font></font><font face="C&#111;nsolas">) Principal.Identity).UserID;</font></p><font face="C&#111;nsolas"><p>            </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">foreach</font></font><font face="C&#111;nsolas"> (</font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">var</font></font><font face="C&#111;nsolas"> entity </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">in</font></font><font face="C&#111;nsolas"> entitiesBeingUpdated)</font></p><font face="C&#111;nsolas"><p>            {</p><p>                </p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">var</font></font><font face="C&#111;nsolas"> audit = EntityManager.CreateEntity&lt;</font><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">Audit</font></font><font face="C&#111;nsolas">&gt;();</font></p><font face="C&#111;nsolas"><p>                audit.EntityAspect.AddToManager();</p><p>                audit.AuditTime = </p></font><p><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">DateTime</font></font><font face="C&#111;nsolas">.Now;</font></p><font face="C&#111;nsolas"><p>                audit.AuditType = auditType;</p><p>                audit.EntityName = entity.GetType().Name;</p><p>                audit.EntityID = (</p></font><p><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">long</font></font><font face="C&#111;nsolas">)entity.GetType().GetProperty(</font><font color="#a31515" face="C&#111;nsolas"><font color="#a31515" face="C&#111;nsolas">"ID"</font></font><font face="C&#111;nsolas">).GetValue(entity, </font><font color="#0000ff" face="C&#111;nsolas"><font color="#0000ff" face="C&#111;nsolas">null</font></font><font face="C&#111;nsolas">); </font><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas">// All our tables have a "ID" column storing the identity value.</font></font></p><font color="#008000" face="C&#111;nsolas"><font color="#008000" face="C&#111;nsolas"></font></font><font face="C&#111;nsolas"><p>                audit.ChangeByID = userId;</p><p>            }</p><p>        }</p><p>    }</p></font></font></div><div><font face="C&#111;nsolas"></pre></td></tr></table></div><p>&nbsp;</p></font>]]>
   </description>
   <pubDate>Thu, 26 May 2011 17:02:53 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10845#10845</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns : Wokket,  Is tue audit table...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10844#10844</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1097" rel="nofollow">robertg</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 26-May-2011 at 4:56pm<br /><br />Wokket,<DIV>&nbsp;</DIV><DIV>Is tue audit table in your entity model, with a FK relationship defined back to your data table? It seems that if it was, you should be able to execute the save in a single transaction, since EF will&nbsp; create populate the correct information into the navigation properly.</DIV><DIV>&nbsp;</DIV><DIV>If that's not the case, could you post your save interceptor here so we can take a look at it?</DIV><DIV>&nbsp;</DIV><DIV>Thanks,</DIV><DIV>-- Robert</DIV>]]>
   </description>
   <pubDate>Thu, 26 May 2011 16:56:15 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10844#10844</guid>
  </item> 
  <item>
   <title>Auditing Inserts with Identity columns :   G&amp;#039;day again guys,I&amp;#039;m...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10825#10825</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1155" rel="nofollow">Wokket</a><br /><strong>Subject:</strong> 2717<br /><strong>Posted:</strong> 25-May-2011 at 5:41pm<br /><br />G'day again guys,<div>&nbsp;</div><div>I'm chasing some advice about auditing inserts of data where we are using Identity columns in the database for ID's.</div><div>&nbsp;</div><div>I've created an EntityServerSaveInterceptor derived class, overrriden ExecuteSave() and am successfully auditing updates to existing data.</div><div>&nbsp;</div><div>When it comes to inserts however, we (obviously) cannot get the ID value of the freshly inserted row until after the call to base.ExecuteSave() as we're using Identity columns.</div><div>&nbsp;</div><div>I've attempted to call base.ExecuteSave() a second time to insert the Audit records, however they don't seem to be detected as pending entities, the system attempts to insert the original data again.</div><div>&nbsp;</div><div>Variants of EntityManager.SaveChanges() fail due to recursive saves not being supported.</div><div>&nbsp;</div><div>Can anyone shed some light on whether this is possible? It seems like a pretty common requirement, I'm coming up short atm.</div><div>&nbsp;</div><div>Cheers,</div><div><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas"></font></font>&nbsp;</div><div><font color="#2b91af" face="C&#111;nsolas"><font color="#2b91af" face="C&#111;nsolas">&nbsp;</div></font></font>]]>
   </description>
   <pubDate>Wed, 25 May 2011 17:41:25 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=2717&amp;PID=10825#10825</guid>
  </item> 
 </channel>
</rss>