Historic values in LINQ

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nils Magnus

    Historic values in LINQ

    Hello, I've just started using SQL to LINQ to access my SQL Server
    tables, and it's a wonderful tool. Are there any equally elegant ways to
    store and access historic values for the objects?

    For instance, I'm managing a Person table with mail addresses, phone
    numbers etc. I would like to be able to store the earlier values of
    these fields, so I can see what mail address/phone number a given Person
    had at a specific point in time.

    Any tips and links to guides etc. would be very appreciated!

    Thanks.


    Regards,
    Nils Magnus
  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: Historic values in LINQ

    Nils Magnus wrote:
    Hello, I've just started using SQL to LINQ to access my SQL Server
    tables, and it's a wonderful tool. Are there any equally elegant ways to
    store and access historic values for the objects?
    >
    For instance, I'm managing a Person table with mail addresses, phone
    numbers etc. I would like to be able to store the earlier values of
    these fields, so I can see what mail address/phone number a given Person
    had at a specific point in time.
    >
    Any tips and links to guides etc. would be very appreciated!
    There is no support for historic data in the database, so you would have
    to store it as regular data, and to get a time line you would add
    information about the time interval when the data is valid.

    As you want to be able to store multiple values for each Person record,
    you need to store them in a separate table. You can either store each
    piece of information in a single table by adding a field for what type
    of information it is, or have separate tables for address, phone, et.c.

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • Arved Sandstrom

      #3
      Re: Historic values in LINQ

      "Nils Magnus" <nmee@nmee.netw rote in message
      news:eTcBl%23Uy IHA.4864@TK2MSF TNGP06.phx.gbl. ..
      Hello, I've just started using SQL to LINQ to access my SQL Server tables,
      and it's a wonderful tool. Are there any equally elegant ways to store and
      access historic values for the objects?
      >
      For instance, I'm managing a Person table with mail addresses, phone
      numbers etc. I would like to be able to store the earlier values of these
      fields, so I can see what mail address/phone number a given Person had at
      a specific point in time.
      >
      Any tips and links to guides etc. would be very appreciated!
      >
      Thanks.
      >
      Regards,
      Nils Magnus
      {X-posted to cljd for extra comment]

      As Göran pointed out there is no explicit support for this in a database,
      because this historical information is itself data. That is, it's not (in
      this scenario) metadata, because you specifically stated "so I can see what
      mail address/phone number a given Person had at a specific point in time."

      Since you're planning an address book, one thing you've likely already
      considered is that a Person may have multiple _current_ addresses. In fact,
      since one Address may also be associated with multiple Persons, you have a
      many-to-many relationship, usually best implemented as a join table with at
      least one attribute to describe the "name" of the relationship between that
      Person and that Address. For example, "summer cottage".

      For your purposes you could add the date information to that join table. Or
      more realistically, have fields for start and end dates, but assume that
      these fields will often be empty. After all, how many people have this kind
      of data for their contacts? Without some research I couldn't even tell you
      what *my* addresses have been to an accuracy of a month, let alone exact
      dates.

      If doing just the above, you'd then likely want a current flag in that join
      table also, which would indicate which Person-Address combinations are
      current. At this stage you'd be able to say, at a minimum, this Person
      presently has these addresses, but at various times in the past they have
      also had these addresses.

      An interesting situation arises at this point - what happens if a Person was
      once at Address A, then afterwards was at Address B, but now is back at
      Address A? We've already established that start and end dates may be
      unobtainable, so distinguishing between "Person-Address A Now" and
      "Person-Address A Then" cannot depend on those fields. One way around this
      is to add yet another field to the join table, which would participate along
      with the Person ID and the Address ID in the join table primary key. I
      myself would assign no extra meaning to this field, except that it be unique
      for a given address. At this stage you'd be able to say, at a minimum, this
      Person presently has these addresses, but at various times in the past
      they've had these others, and I can see that one of the current addresses
      was also a past address (for example).

      Finally, because it very often _is_ quite easy to say, "I don't know exactly
      _when_ Arved lived at addresses A, B, and C, but I do know that he lived at
      A, then B, then A again, and now he's at C", you could have one final field
      in the join table, which is a date sequence number (for lack of a better
      term). Since re-arrangement operations on this field (changes due to past
      address inserts etc) will be infrequent, your numbering convention is not
      critical. If using this scheme you will however have to have a "don't know"
      value.

      At this (rather elaborate) stage you could say that this Person currently
      has these addresses, but at various times in the past they've had these
      others, one of the current addresses was a past address, and another past
      address was used twice. Not only that, I know (because of the date sequence
      number) how long (relatively) the person has had the current addresses, and
      for 3 of the 5 past addresses I know which came before or after.

      For phone numbers and email addresses I myself would not use such a detailed
      system. Strictly speaking both also participate in many-to-many
      relationships with Person, particularly PhoneNumber, but I myself would be
      satisfied with the information that such-and-such a Person currently has
      EmailAddress EA1 and EA2, and in the past has also had EA3 and EA4. So the
      start date, end date and date sequence fields could be omitted in these join
      tables.

      This is obviously open to debate. It's merely a system I might consider had
      I to implement your requirement.

      AHS


      Comment

      • Peter Morris

        #4
        Re: Historic values in LINQ

        You need to model it.

        Person 0..* ----- 0..* Address

        When you refer to something refer to both the person and the address at
        which they received the goods (or whatever).


        --
        Pete
        =============== =============== ===========
        I use Enterprise Core Objects (Domain driven design)

        =============== =============== ===========


        Comment

        • Lew

          #5
          Re: Historic values in LINQ

          Arved Sandstrom wrote:
          This is obviously open to debate. It's merely a system I might consider had
          I to implement your requirement.
          This type of data modeling cries out for a standard data-warehouse star
          schema, with fact and dimension tables.

          --
          Lew

          Comment

          • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

            #6
            Re: Historic values in LINQ

            Arved Sandstrom wrote:
            {X-posted to cljd for extra comment]
            Why cljd and not any other database group ??

            Arne

            Comment

            • Arved Sandstrom

              #7
              Re: Historic values in LINQ

              "Arne Vajhøj" <arne@vajhoej.d kwrote in message
              news:484bf28c$0 $90273$14726298 @news.sunsite.d k...
              Arved Sandstrom wrote:
              >{X-posted to cljd for extra comment]
              >
              Why cljd and not any other database group ??
              >
              Arne
              Well, it's the only database-oriented NG I follow, and I thought that
              getting the subject into at least one such NG would be useful.

              In hindsight it's a topic that, suitably reworded to make it somewhat more
              encompassing, would be interesting in a more general database-oriented
              group.

              AHS


              Comment

              • Arved Sandstrom

                #8
                Re: Historic values in LINQ

                "Lew" <conrad@lewscan on.com.invalidw rote in message
                news:EN6dnaRwDt 14dNbVnZ2dnUVZ_ gCdnZ2d@comcast .com...
                Arved Sandstrom wrote:
                >This is obviously open to debate. It's merely a system I might consider
                >had I to implement your requirement.
                >
                This type of data modeling cries out for a standard data-warehouse star
                schema, with fact and dimension tables.
                --
                Lew
                Agreed.

                AHS


                Comment

                • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

                  #9
                  Re: Historic values in LINQ

                  Arved Sandstrom wrote:
                  "Arne Vajhøj" <arne@vajhoej.d kwrote in message
                  news:484bf28c$0 $90273$14726298 @news.sunsite.d k...
                  >Arved Sandstrom wrote:
                  >>{X-posted to cljd for extra comment]
                  >Why cljd and not any other database group ??
                  >
                  Well, it's the only database-oriented NG I follow, and I thought that
                  getting the subject into at least one such NG would be useful.
                  >
                  In hindsight it's a topic that, suitably reworded to make it somewhat more
                  encompassing, would be interesting in a more general database-oriented
                  group.
                  microsoft.publi c.sqlserver.pro gramming
                  microsoft.publi c.dotnet.framew ork.adonet
                  comp.databases. sqlserver

                  were some of the other possibilities.

                  But it is not obvious exactly where the questions belongs.

                  I was just puzzled that you picked the Java one.

                  Arne

                  Comment

                  • Alun Harford

                    #10
                    Re: Historic values in LINQ

                    Nils Magnus wrote:
                    Hello, I've just started using SQL to LINQ to access my SQL Server
                    tables, and it's a wonderful tool. Are there any equally elegant ways to
                    store and access historic values for the objects?
                    >
                    For instance, I'm managing a Person table with mail addresses, phone
                    numbers etc. I would like to be able to store the earlier values of
                    these fields, so I can see what mail address/phone number a given Person
                    had at a specific point in time.
                    I've had to do this in a medical context (where this stuff is hugely
                    important, together with information about who made which changes), so I
                    guess I can be pretty helpful here. I've not played with the guts of
                    Linq-to-SQL - it's too much of a step backwards for me... the Entity
                    Framework looks better - version 2 of the Entity Framework even looks
                    like it'll support POCO, so it might even compete with NHibernate at
                    that point.

                    In NHibernate 2 (still technically in alpha, but it's pretty stable in
                    my opinion), you can add an event listener so you can be notified when
                    any entity is pushed from your CLR objects into the database and attach
                    history at that point. This works well in my experience.

                    Alun Harford

                    Comment

                    • =?Utf-8?B?UGFua2Fq?=

                      #11
                      RE: Historic values in LINQ

                      Please go to http://www.a2zdotnet.com/Default.aspx
                      for step by step tutorials for beginers in LINQ sections.

                      --
                      regards,
                      Pankaj



                      "Nils Magnus" wrote:
                      Hello, I've just started using SQL to LINQ to access my SQL Server
                      tables, and it's a wonderful tool. Are there any equally elegant ways to
                      store and access historic values for the objects?
                      >
                      For instance, I'm managing a Person table with mail addresses, phone
                      numbers etc. I would like to be able to store the earlier values of
                      these fields, so I can see what mail address/phone number a given Person
                      had at a specific point in time.
                      >
                      Any tips and links to guides etc. would be very appreciated!
                      >
                      Thanks.
                      >
                      >
                      Regards,
                      Nils Magnus
                      >

                      Comment

                      Working...