Ric*_*tts 3 database sql-server database-design entity-framework domain-model
我有一个数据库,持有房地产MLS(多重上市服务)数据.目前,我有一个表,其中包含所有列表属性(价格,地址,平方英尺等).有几种不同的属性类型(住宅,商业,租赁,收入,土地等),每种属性类型共享大多数属性,但有一些属性类型是唯一的.
我的问题是共享属性超过250个字段,这似乎在一个表中有太多字段.我的想法是我可以将它们分解为EAV(实体 - 属性 - 值)格式,但我已经阅读了很多关于它的不好的事情,它会使运行查询变得非常痛苦,因为可以搜索250个字段中的任何一个.如果我要去那条路线,我真的必须从EAV表中提取所有数据,按列表ID分组,将其合并到应用程序端,然后针对内存对象集合运行我的查询.这似乎也不是很有效.
我正在寻找关于以何种方式进行的一些想法或建议.也许250+字段表是唯一的方法.
就像一张纸条,我正在使用SQL Server 2012,.NET 4.5 w/Entity Framework 5,C#,数据通过WCF服务传递给asp.net Web应用程序.
提前致谢.
让我们考虑替代品的利弊:
所有列表+属性的一个表格:
context.Listings.Where(l => l.PricePerMonthInUsd < 10e3 && l.SquareMeters >= 200)
.ToList();
Run Code Online (Sandbox Code Playgroud)
一个表用于所有列表,一个表用于属性类型,一个用于(列出ID +属性IDS +)值(EAV):
var listingIds = context.AttributeValues.Where(v =>
v.AttributeTypeId == PricePerMonthInUsdId && v < 10e3)
.Select(v => v.ListingId)
.Intersection(context.AttributeVales.Where(v =>
v.AttributeTypeId == SquareMetersId && v.Value >= 200)
.Select(v => v.ListingId)).ToList();
Run Code Online (Sandbox Code Playgroud)
或:(比较实际DB的性能)
var listingIds = context.AttributeValues.Where(v =>
v.AttributeTypeId == PricePerMonthInUsdId && v < 10e3)
.Select(v => v.ListingId).ToList();
listingIds = context.AttributeVales.Where(v =>
listingIds.Contains(v.LisingId)
&& v.AttributeTypeId == SquareMetersId
&& v.Value >= 200)
.Select(v => v.ListingId).ToList();
Run Code Online (Sandbox Code Playgroud)
然后:
var listings = context.Listings.Where(l => listingIds.Contains(l.ListingId)).ToList();
Run Code Online (Sandbox Code Playgroud)
妥协选项 - 所有列表都有一个表,每组属性包含一个表(包括值)(假设您可以将属性划分为组):
根据您的具体统计数据(关于稀疏性)和需求/可维护性计划(例如,添加/更改属性类型的频率?)来决定利弊.