[dba-VB] CodeFirst, DataBinding and audit trailing deleted items on client side

Salakhetdinov Shamil mcp2004 at mail.ru
Wed Apr 17 06:42:02 CDT 2013


 Hi Doug,

My pleasure!

I have changed the code slightly - added JSON serializer to audit trailed items:

public class AuditTrailItem
{
public AuditTrailItem(System.Data.EntityState itemState, T item, string itemKey)
{
this.ItemState = itemState;
this.Item = item;
this.ItemKey = itemKey;
var serializer = new JavaScriptSerializer();
ItemJSON = serializer.Serialize(item); 
}
public System.Data.EntityState ItemState { get; private set; }
public T Item { get; private set; }
public string ItemKey { get; private set; }
public string ItemJSON { get; private set; }
}
JSON serialization can be done by using System.Web.Script.Serialization.JavaScriptSerializer class. It's needed here as the audit trailed item natural key ([Name] field in my test case) can be changed and then the same item will be present more than one time in audit trail Dictionary<string, AuditTrailItem>.

And then last function of the lengthy class I have posted in my prev. postings will become:

public List<string> GetAuditTrailItemsTestReport(Dictionary<string, AuditTrailItem> auditTrailItems)
{
if (auditTrailItems == null) return new List<string>();
List<string> report = new List<string>();
foreach (var auditTrailItem in auditTrailItems.Values)
{
report.Add(
string.Format(
" {0}: ID = '{1}', Name = '{2}', JSON = '{3}'\n",
auditTrailItem.ItemState.ToString(),
getIDValue(auditTrailItem.Item), getKeyValue(auditTrailItem.Item),
auditTrailItem.ItemJSON) 
);
}
return report;
}

 Thank you.

-- Shamil 
Вторник, 16 апреля 2013, 20:02 -07:00 от Doug Steele <dbdoug at gmail.com>:
>Thank you for posting this, Shamil!
>
>Doug
>
>
>On Tue, Apr 16, 2013 at 7:12 PM, Salakhetdinov Shamil  < mcp2004 at mail.ru > wrote:
>> Here is how the code posted in my two previous postings can be used with a test WinForm with one gridview bound to a DbSet< MyTestEntity> via BidingSource, three test buttons and one test textox. Previously posted and the following code is not used in production nor I plan to use it in production environment soon - this coding is more for learning purposes of CodeFirst approach (  http://www.amazon.com/Programming-Entity-Framework-Code-First/dp/1449312942/ref=sr_1_2?ie=UTF8&qid=1366164644&sr=8-2&keywords=DbContext ) and DbContext (  http://www.amazon.com/Programming-Entity-Framework-Julia-Lerman/dp/1449312969/ref=sr_1_1?ie=UTF8&qid=1366164644&sr=8-1&keywords=DbContext ).
>>
>>using System;
>>using System.Windows.Forms;namespace TestWindowsFormsApplication1
>>{
>>public partial class TestForm : Form
>>{ <<< skipped >>>
>
>>


More information about the dba-VB mailing list