sql-server - 根据 EF Core 中的二级索引获取数据
问题描述
如果我为我的表定义了二级索引(非聚集),我想了解如何在 EF Core 中有效地检索数据。
我希望能够基于二级索引对单个元素进行有效查找:
public class Entity
{
[Key]
public long Id{get;set;}
[Index(IsClustered=false,IsUnique=false)]
public string SecondaryId{get;set;}
}
public class MyContext:DbContext{
public DbSet<Entity> Entities{get;set;}
}
public void Find(long primaryIndex,string SecondaryId,MyContext context)
{
var normalSearch=context.Entities.Find(primaryIndex);
var secondaryIndexSearch=context.Entites.Find(SecondaryId); //does it know to look at the `SecondaryId` column and detect that its a secondary index ?
}
解决方案
推荐阅读
- reactjs - 如何在 React 上仅打开 1 个面板?
- c++ - OpenCV 并从 OutputArrays 或 (Mat) 读取数据
- scala - pac4j-play SecureAction(扩展),类型不匹配
- qemu - sgx:EPC 部分为零
- vue.js - 为什么overflow-x hidden 与客户端边界矩形有交互
- splunk - 如何放置像算术这样的条件输出,值 o/p 应该大于 = 30k 并且小于 = 30 k
- azure - XSLT 在逻辑应用程序中出现异常
- php - SOAP-ERROR: Parsing WSDL: could't load from '...?wsdl' : failed to load external entity
- cordova - 如何使用 adobe phonegap build 在基于 Web 的应用程序中打开 pdf 文件
- elasticsearch - 模糊查询生成器中是否有某种方法可以识别任何记录是否完美匹配?