保存从 EAV 数据库结构加载序列化对象

发布于 2024-10-06 05:55:48 字数 568 浏览 4 评论 0原文

我有一个人员数据库表,其中包含非常基本的姓名、地址、年龄等,每个人都有一个唯一的 ID“personID”。与此相关的是,我有一组 EAV 表来存储每个人可能不同的额外字段。我已经有了将 person 表中的记录保存和加载到 ac# person 对象或 person 对象数组中的代码。但是我不确定如何处理 EAV 记录的加载。我正在考虑向我的 person 对象添加一个名为“属性”的数组,该数组是一个属性数组,每个属性都有一个“名称”和“值”。因此,例如,我可以编写代码“

PersonA.Properties[i].Name = "Age"; 
PersonA.Properties[i].Value = 22;

加载单个对象”似乎没问题,我可以执行 1 个数据库调用来从人员表中加载详细信息,然后进行第二次调用来加载属性或通过一次调用返回 2 个数据集。但是,我如何获得一组人,每个人都有自己的属性数组。如果有人有任何示例的链接,我将不胜感激。如果您能给我有关如何实现属性的提示,那么我也可以加分,这样我就可以编写如下代码:

PersonA.Properties["Age"] = "22";

I have a database table of people which is quite basic name address age etc each with a unique ID "personID". Linked to that i have an EAV set of tables to store extra fields which are potentially different for each person. I've already got code to save and load records from the person table into a c# person object or an array of person objects. However i'm not sure how to handle the loading of the EAV records. I was thinking of adding an array to my person object called "properties" which would be an array of properties each with a "name" and "value". So for example i could code

PersonA.Properties[i].Name = "Age"; 
PersonA.Properties[i].Value = 22;

Loading a single object seems ok i could do 1 database call to load the details from the people table and a second call to load the properties or return 2 datasets with one call. However how do i get an array of people with each person having their array of properties. If anybody has any links to examples i'd be grateful. Also bonus points if you can give me tips on how to implement properties so i can do code like:

PersonA.Properties["Age"] = "22";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雨成花 2024-10-13 05:55:48

对于 SQL Server,我同意 Marc 关于将其放入 xml 的观点。方便查询。

要将代码放入您想要的格式,如果该属性的日期是同质的,我将使用通用字典,然后在其之间来回转换 xml。

With SQL server, I agree with Marc about getting it into xml. Makes it easy to query.

To put the code into the format you want, I would use a generic Dictionary if the date is homogenious for that property and then transform the xml back and forth between that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文