LINQ的历史价值 [英] Historic values in LINQ

查看:53
本文介绍了LINQ的历史价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我刚刚开始使用SQL来LINQ访问我的SQL Server

表,这是一个很棒的工具。有没有同样优雅的方式来存储和访问对象的历史值?


例如,我正在管理一个带有邮件地址的Person表,电话

数字等。我希望能够存储这些字段的早期值

,这样我就可以看到给定人员的邮件地址/电话号码

在特定时间点。


任何提示和指南等链接都将非常感激!


谢谢。

问候,

Nils Magnus

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

推荐答案

Nils Magnus写道:
Nils Magnus wrote:

您好,我刚开始使用SQL来LINQ访问我的SQL Server

表,这是一个很棒的工具。有没有同样优雅的方式来存储和访问对象的历史值?


例如,我正在管理一个带有邮件地址的Person表,电话

数字等。我希望能够存储这些字段的早期值

,这样我就可以看到给定人员的邮件地址/电话号码

在特定时间点。


任何提示和指南等链接都将非常感激!
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!



数据库中不支持历史数据,因此您可以将

存储为常规数据,并获得时间线你会添加

有关数据有效的时间间隔的信息。


因为你希望能够为每个人记录存储多个值,

您需要将它们存储在单独的表中。您可以将每个

的信息存储在一个表中,方法是添加一个类型的字段,或者有一个单独的地址,电话等表格。 .c。


-

G?跑Andersson

_____
http://www.guffa.com


" Nils Magnus" ; < nm ** @nmee.netwrote in message

news:eT **************** @ TK2MSFTNGP06.phx.gbl ...
"Nils Magnus" <nm**@nmee.netwrote in message
news:eT****************@TK2MSFTNGP06.phx.gbl...

您好,我刚开始使用SQL来LINQ来访问我的SQL Server表,

这是一个很棒的工具。是否有任何同样优雅的方式存储和

访问对象的历史值?


例如,我正在管理一个带有邮件地址的Person表,手机

数字等我希望能够存储这些

字段的早期值,这样我就可以看到给定人员的邮件地址/电话号码了在

a特定时间点。


任何提示和指南等链接都将非常感激!


谢谢。


问候,

Nils Magnus
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额外评论]


由于G?ran指出在数据库中没有明确的支持,因为这个历史信息本身就是数据。也就是说,它不是(在这个场景中的b $ b)元数据,因为你明确说明了所以我可以看到什么

邮件地址/电话号码给定的人在某个特定的时间点。


因为你正在计划一本地址簿,你可能已经考虑过的一件事是b
一个人可能有多个_current_地址。事实上,

因为一个地址也可能与多个人关联,你有一个多对多的关系,通常最好实现为与<的连接表br />
至少一个用于描述名称的属性。

人与该地址之间的关系。例如,summer cottage。


为了您的目的,您可以将日期信息添加到该连接表。或者更实际地,
有开始和结束日期的字段,但是假设这些字段通常是空的。毕竟,有多少人为他们的联系人提供了这种类型的数据?没有一些研究,我甚至不能告诉你

*我的*地址已达到一个月的准确度,更不用说确切的

日期。


如果只是做上述事情,那么你可能还想要在该连接中使用当前标志

表,这将表明哪些人员地址组合

当前。在这个阶段,你至少可以说这个人

目前有这些地址,但在过去的不同时间他们也有b $ b b这些地址。


在这一点上出现了一个有趣的情况 - 如果一个人在地址A处获得
,然后在地址B处,那么会发生什么?现在又回到了

地址A?我们已经确定开始和结束日期可能是无法获得的,因此可以区分人员地址A现在和人员地址A现在。和

人员地址A然后不能依赖那些领域。围绕这个

的另一种方法是在连接表中添加另一个字段,该字段将与连接表主键中的人员ID和地址ID一起参与

。我自己不会为这个字段分配额外的含义,除了它是唯一的
给定地址的
。在这个阶段你至少可以说这个

人目前有这些地址,但在过去的不同时间

他们已经有这些其他的,我可以看到当前地址之一

也是过去的地址(例如)。


最后,因为它经常_is_很容易说,我完全不知道

_when_ Arved住在地址A,B和C,但我确实知道他住在

A,然后是B,然后又是A,现在他在C,你可以在连接表中有一个最终字段

,这是一个日期序列号(缺少一个更好

term)。由于此字段的重新安排操作(由于过去的

地址插入等更改)将很少发生,因此您的编号约定不是很重要。如果使用这个方案,你将不得不有一个不知道

的价值。


在这个(相当复杂的)阶段,你可以说这个人目前

有这些地址,但在过去的不同时间他们已经有了这些

其他人,其中一个当前地址是过去的地址,和另一个过去的

地址被使用了两次。不仅如此,我知道(因为日期顺序

数字)这个人有多长时间(相对)有当前地址,并且

为过去5个中的3个地址我知道之前或之后的地址。


对于电话号码和电子邮件地址,我自己不会使用这么详细的

系统。严格来说,两者都参与了与Person之间的多对多
关系,特别是PhoneNumber,但我自己会对这样的信息感到满意。此人目前拥有

EmailAddress EA1和EA2,而且过去也有过EA3和EA4。所以

开始日期,结束日期和日期序列字段可以在这些加入

表中省略。


这显然是开放辩论。它只是一个我可能会考虑的系统

我来实现你的要求。


AHS

{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


你需要建模它。


人0 .. * ----- 0 .. *地址


当你是指他们收到货物(或其他)的人和地址都指的是



-

Pete

========================================= />
我使用企业核心对象(域驱动设计)
http:/ /www.capableobjects.com/

=============================== ==========
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)
http://www.capableobjects.com/
=========================================


这篇关于LINQ的历史价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆