This project is read-only.

AuditPropertyResolver

Jan 15, 2010 at 7:49 PM

Has anyone been able to implement this? If so could someone please explain how to get this to function correctly?

I have multiple tables that I will need to implement custom properties for so Im assuming I will need to create an AuditPropertyResolver for each table...but Im not sure how its suppose to be implemented.

 

Any suggestions would be greatly appreciated.


Thanks

Jerami

Jan 26, 2010 at 7:33 PM

Bump

Jan 26, 2010 at 7:57 PM

Heath - Here is an example that I have working

ProjectBudget is the name of my datatable in Linq

AuditResolver is a type that you will get from the DoodleLinq reference

ProjectBudgetAuditResolver is a custom class that implements AuditPropertyResolver<YourDataTable>

Hope the examples below help

[AuditResolver(typeof(ProjectBudgetAuditResolver))]
    public partial class ProjectBudget
    {

    }

    public class ProjectBudgetAuditResolver : AuditPropertyResolver<ProjectBudget>
    {
        protected override void CustomizeProperties()
        {
            CustomizeProperty(p => p.BudgetSourceId, sourceId => GetProjectBudgetSource(sourceId), "ProjectBudgetSource");
        }

        public string GetProjectBudgetSource(int id)
        {
            var result = new ConverseDataContext();
            var query = (result.BudgetSources.Where(ab => ab.BudgetSourceId == id)).FirstOrDefault();
            return query.Name;
        }
    }

Here is another class I created for a different table

[AuditResolver(typeof(TacticAuditResolver))]
    public partial class ProjectTactic
    {

    }

    public class TacticAuditResolver : AuditPropertyResolver<ProjectTactic>
    {
        protected override void CustomizeProperties()
        {
            CustomizeProperty(p => p.TacticSourceId, sourceId => GetTacticSource(sourceId), "TacticSource");
        }

        public string GetTacticSource(int id)
        {
            var result = new ConverseDataContext();
            var query = (result.TacticSources.Where(ab => ab.TacticSourceId == id)).FirstOrDefault();
            return query.Name;
        }
    }

Jan 27, 2010 at 5:56 PM

I had my decorator wrong.  Thanks, Jerami.

Feb 2, 2010 at 10:09 PM

Where do you put the ProjectBudgetAuditResolver class?  Does it need to be in a specific class file, or do you have to instantiate it somehow?  I'm trying to get this to work with Visual Basic.  As far as I can tell I have the code in place, but the CustomizeProperties() method never gets called.  Here's the code that I've written.  I put breakpoints all over it, but it never seems to get called. 

 

Public Class TABLEAuditResolver
    Inherits AuditPropertyResolver(Of TABLE_NAME)

    Protected Overloads Overrides Sub CustomizeProperties()
        CustomizeProperty(Function(p) p.tblStorageContainer, Function(p) p.tblContainer.Alias, "Container")
    End Sub

End Class

Any ideas?

Thanks!

Seth

Feb 3, 2010 at 4:21 PM

Never mind, I answered my own question.  In case there are any other vb developers out there that are looking for some help, here's the code that I used.  Note: this is in the same project as the LINQ data context. 

<AuditResolver(GetType(TABLEAuditResolver))> _
Partial Public Class tblTABLE

End Class
Public Class TABLEAuditResolver
    Inherits AuditPropertyResolver(Of tblTABLE)
    Protected Overloads Overrides Sub CustomizeProperties()
              
        CustomizeProperty(Function(p) p.StorageContainerID, Function(p) GetContainerName(p), "Container")
    End Sub

    Private Function GetContainerName(ByVal StorageContainerID As Short?) As String
        'code to get container name
    End Function

End Class
Jul 14, 2010 at 7:51 PM

Kevin,

What did you change in your code to get it to call CustomizeProperties?  I am having the same problem (in C#) - my CustomizeProperties (override) routine never gets called.

- Tim