L&H_Reader新闻阅读器?(L&H_Reader news reader? What's this?)
消息源显示
用户代理:L&H_Reader
这是什么新闻阅读器?
A message source shows
User-Agent: L&H_Reader
What news reader is this?
原文:https://stackoverflow.com/questions/2049540
最满意答案
你正在使用什么样的数据库模式? 通常,这是关系应该存储的地方,我认为这应该在数据处理级而不是代码上。
这是一个非常简单的建议
保险(<insurance_id>,名称,说明)
insurance_item(<item_id>,<insurance_id>,名称,说明)
insurance_item_details(<item_id>,<policy_id>,when_changed)
insurance_policy与insurance_item有一对多的关系。 insurance__item与insurance_item_details有一对多的关系。 insurance__item__details中的每一行代表政策的变化。
这样,SQL可以快速检索最新的两个项目
SELECT FROM insurance_item_details, insurance_item, insurance where insurance_item_details.item_id = insurance_item.item_id AND insurance_item.insurance_id = insurance.insurance_id ORDER BY when_changed LIMIT 1
或者你甚至可以检索历史。
(该SQL尚未尝试过)
因此,您的想法是不重复insurance_item - 您有另一个表来存储将被更改的元素,并用它拍摄一个时间戳,将该更改表示为关系。
我不是SQL专家(不幸),但是你只需要插入到insurance_item_details表中,而不是复制副本。 从它看起来的方式来看,像我最初的例子那样制作副本似乎违反了2NF,我想。
Thanks everyone who has provided answers. Unfortunately, due to conditions at work I'm unable to implement database changes and am stuck trying to make due with a coding solution.
After spending some time over the weekend on this problem I have come up with a solution that I believe simplifies the code a bit even though it is still nowhere near perfect.
I extracted the functionality out into a new method and pass in the master policy that I want the new policy linked to.
Policy Convert(Policy policy, Policy masterPolicy) { Policy newPolicy = policyManager.Copy(policy); //link the policy to it's master policy if(masterPolicy != null) { newPolicy.MasterPolicyId = masterPolicy.Id; } SavePolicy(newPolicy); //inactivate the current policy policy.Status = Inactive; policyManager.UpdatePolicy(policy); return newPolicy; }
This allows me to then loop through all the policies and pass in the policy that needs to be linked as long as the policies are sorted in the correct order...which in my case is by start date and then by master policy id.
Policy newPolicy = null; foreach(Policy policy in policyList) { Policy masterPolicy = policy.MasterPolicyId.HasValue ? newPolicy : null; newPolicy = Convert(policy, masterPolicy); }
When all is said and done, it isn't all that much less code but I believe it is much more understandable and it allows individual policies to be converted.
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
SQL中的链接列表(Linked List in SQL)[2022-10-21]
在您的表中存储一个称为“position”的整数列。 为列表中的第一个项目记录一个0,第二个项目的第一个项目记录一个等。数据库中的该列的索引,当您要拉出值时,按该列排序。 alter table linked_list add column position integer not null default 0; alter table linked_list add index position_index (position); select * from linked_list order by ... -
如何最轻松地从XLS导入我的rails应用程序数据库?(How do I most easily import from XLS into my rails app database?)[2023-10-15]
尝试这个: 如何将CSV文件数据导入PostgreSQL表? 简而言之,您基本上设置了一个CSV文件,该文件反映了您要导入的数据库表的结构 如果您必须对数据进行一些操作,您可能会发现更容易编写读取现有CSV格式文件的内容并为每行创建数据库记录。 使用csv gem或类似的东西: https://github.com/pillowfactory/csv-mapper Try this: How to import CSV file data into a PostgreSQL table? In short ... -
所以要澄清一下......你有从SharePoint导出的项目数据和Access中的项目数据,理想情况下你想要合并它们并将结果存储在Access中。 或者也许是另一种方式,您希望使用SharePoint中的数据来补充Access中的数据。 如果为SharePoint报告提供支持的数据库也在Access中运行,则您要查找的单词是复制 。 您希望自动将数据从一个服务器/数据库复制到另一个服务器/数据库。 不幸的是,我不知道任何将数据复制到Access的软件。 您最好的选择是编写一个计划运行SharePoint报 ...
-
打开与非本地Access数据库文件的连接(即,不是与Access窗体相同的.accdb / .mdb中的表)往往具有大约5秒的“刷新率”。 这似乎是ACE / Jet数据库引擎的功能。 我在这里的另一个答案是指OLEDB连接,但它也可以很好地应用于DAO连接。 Open connections to Access database files that are not local (i.e., not a table in the same .accdb/.mdb as the Access form) t ...
-
我不知道您的要求是否使用链接列表但如果不是,请使用Set而不是List(您将问题标记为'best-practices') I don't know if your requirements is to use a linked list but if not, use a Set instead of a List (you tagged the question as 'best-practices')
-
你正在使用什么样的数据库模式? 通常,这是关系应该存储的地方,我认为这应该在数据处理级而不是代码上。 这是一个非常简单的建议 保险(
,名称,说明) insurance_item( , ,名称,说明) insurance_item_details( , ,when_changed) insurance_policy与insurance_item有一对多的关系。 insurance__item与insura ... -
如何在SQL数据库中轻松选择或标记最新的重复项(How to easily select or mark latest duplicates in a SQL database)[2022-07-08]
尝试 SELECT * FROM t1 where (`order`,`batch`,`lot`,`item`,`tstamp`) in ( select `order`,`batch`,`lot`,`item`, max(`tstamp`) from t1 GROUP BY `order`, `batch`, `lot`, `item` ); 或者只列出一个选择查询中的所有列,如果没有多少: select `order`,`batch`,`lot`,`item`, max ... -
您可以考虑以下中央数据库架构: stores id code name address ... items id code name description barcode retail_price ... stocks store_id item_id stock_count inventories id inventory_date store_id i ...
-
实体框架有一个名为“模型优先”的概念,它从您的模型生成数据库模型,因此得名。 你可以在这里阅读: http : //msdn.microsoft.com/en-us/data/ff830362 然而,我个人最喜欢的对象关系映射器是NHibernate,加上Fluent NHibernate。 它们有一个概念,您可以使用域模型而不是数据模型,并使用约定来控制映射。 它非常整洁。 您可以通过以下代码查看一些非常好的示例: https : //github.com/sharparchitecture/Northw ...