c# - 如何根据比较分组 ID 使列唯一
问题描述
我需要确保特定站点元素的所有视图数据都是唯一的,但我希望能够为具有不同 ID 的其他站点重用该值。
例子:
站点一
- 查看一个参考:ViewOne
- 查看两个参考:ViewOne <-- 错误
站点二
- 查看一个参考:ViewOne <--没有错误,因为它是一个不同的站点
- 查看二参考:ViewTwo
查看型号:
public class View : AssetsBase, IView
{
public int SiteId { get; set; }
public string Name { get; set; }
public string Ref { get; set; }
public virtual IEnumerable<MetaEntry> MetaEntries { get; set; } = new HashSet<MetaEntry>();
public virtual IEnumerable<HreflangEntry> HreflangEntries { get; set; } = new HashSet<HreflangEntry>();
}
数据库上下文:
builder.Entity<View>().ToTable("SiteView").HasIndex(sw => sw.Ref).IsUnique();
当前方法按预期工作,但我仅限于使用一次 Ref 值。我想要的可能吗?
解决方案
感谢提供解决方案的 user700390。
数据库上下文:
builder.Entity<View>().ToTable("SiteView").HasIndex(sw => new { sw.Ref, sw.SiteId }).IsUnique();
推荐阅读
- netlogo - 如何创建创建(或拥有)具有特定属性的对象的海龟?
- pandas - Pandas 插值:{ValueError}无效的填充方法。期待填充 (ffill) 或回填 (bfill)。得到线性
- postman - 组织实体份额统计返回负字段
- r - 如何根据属性绘制带有颜色的 igraph 社区?
- javascript - 所有 setTimeout 完成后节点脚本不退出
- c# - 当我必须向 HTTP 请求发送有效负载时,是否应该使用 PUT 而不是 DELETE?
- ios - facebook广告设置问题
- java - Android:NullPointerException:尝试调用虚拟方法“布尔”
- java - 在代理服务器中以 HTTPS 建立连接时出现问题。(CONNECT 方法)
- firefox - 如何在 Firefox DevTools 的网络面板中过滤多个域?