Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WPF / EF & 'Audit' field updates

WPF / EF & 'Audit' field updates

Scheduled Pinned Locked Moved C#
wpfcsharparchitectureannouncement
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cjb110
    wrote on last edited by
    #1

    I've got an WPF application (without MVVM or similar), using EF6 (via a OData Webservice) and I wondering whats the best place to update some 'audit' fields. i.e. one entity looks like

    public class ActionStatus
    {
    public int Id {get;set;}
    public string ActionStatus{get;set;}

    [DataType(DataType.Date)]
    public DateTime ValidFrom { get; set; }

    [DataType(DataType.Date)]
    public DateTime ValidTo { get; set; }

    public string ChangedBy { get; set; }
    public DateTime ChangedOn { get; set; }
    }

    So on the WPF side I've got this displayed in a DataGrid, which saves the data back etc, all good so far. For the ChangedBy and ChangedOn fields I want the 'system' to update these as required. But I'm not sure where it would go! Doing it on the DataGrid events, seems very wrong...far too late, and would need to be done differently if I didn't use a datagrid in the future. The other places, are the OData WebService, the EF Model, or in the entities themselves, or maybe as another part of the 'system', not sure... I presume that this is one of the 'lots of solutions/it depends' type of problems, but some guidance would be helpful.

    L 1 Reply Last reply
    0
    • C cjb110

      I've got an WPF application (without MVVM or similar), using EF6 (via a OData Webservice) and I wondering whats the best place to update some 'audit' fields. i.e. one entity looks like

      public class ActionStatus
      {
      public int Id {get;set;}
      public string ActionStatus{get;set;}

      [DataType(DataType.Date)]
      public DateTime ValidFrom { get; set; }

      [DataType(DataType.Date)]
      public DateTime ValidTo { get; set; }

      public string ChangedBy { get; set; }
      public DateTime ChangedOn { get; set; }
      }

      So on the WPF side I've got this displayed in a DataGrid, which saves the data back etc, all good so far. For the ChangedBy and ChangedOn fields I want the 'system' to update these as required. But I'm not sure where it would go! Doing it on the DataGrid events, seems very wrong...far too late, and would need to be done differently if I didn't use a datagrid in the future. The other places, are the OData WebService, the EF Model, or in the entities themselves, or maybe as another part of the 'system', not sure... I presume that this is one of the 'lots of solutions/it depends' type of problems, but some guidance would be helpful.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      That's not an audit-trail, but an indication who made the last change. It'd be an audit if it is a complete trace.

      cjb110 wrote:

      .far too late, and would need to be done differently if I didn't use a datagrid in the future.

      The database - that way it won't matter whether it's a webservice, a WinForm or any other UI/app reading from the database. I'd recommend implementing the bare necessities, and nothing more.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      C 1 Reply Last reply
      0
      • L Lost User

        That's not an audit-trail, but an indication who made the last change. It'd be an audit if it is a complete trace.

        cjb110 wrote:

        .far too late, and would need to be done differently if I didn't use a datagrid in the future.

        The database - that way it won't matter whether it's a webservice, a WinForm or any other UI/app reading from the database. I'd recommend implementing the bare necessities, and nothing more.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        C Offline
        C Offline
        cjb110
        wrote on last edited by
        #3

        Eddy Vluggen wrote:

        That's not an audit-trail, but an indication who made the last change.

        heh, I realise, couldn't think of a better term for it.

        Eddy Vluggen wrote:

        The database - that way it won't matter whether it's a webservice, a WinForm or any other UI/app reading from the database.

        As EF is 'creating' my database, and with migrations keeping it up to date, does that mean I add it there as C# code? Or somehow make the migrations side run additional sql to either add trigger or constraint etc?

        L 1 Reply Last reply
        0
        • C cjb110

          Eddy Vluggen wrote:

          That's not an audit-trail, but an indication who made the last change.

          heh, I realise, couldn't think of a better term for it.

          Eddy Vluggen wrote:

          The database - that way it won't matter whether it's a webservice, a WinForm or any other UI/app reading from the database.

          As EF is 'creating' my database, and with migrations keeping it up to date, does that mean I add it there as C# code? Or somehow make the migrations side run additional sql to either add trigger or constraint etc?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          cjb110 wrote:

          run additional sql to either add trigger

          :thumbsup: That way it would be automagically added/updated whenever someone mutates a record.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups