使用 LINQ 和 EF 进行全文搜索
我正在尝试使用 EntityFramework 实现全文搜索。
我的数据库有一个名为 Users 的表和一个名为 UserInfoEntries 的表。表 users 连接到其他一些表,表 UserInfoEntries 包含用户信息。
当我想获取用户信息时,我会浏览 User.UserInfoEntries 中的条目并获取具有最旧条目时间戳的条目。
我想要用作全文搜索键的属性是 UserInfoEntry 中的 FullName 属性。
用于获取具有确切 FullName 的用户的 LINQ 如下所示:
from user in objectContext.Users
let currentInfoEntry =
(from entry in user.UserInfoEntries
orderby entry.EntryTimestamp descending
select entry
).FirstOrDefault()
where currentInfoEntry.FullName == "Some Name"
select new UserWithInfo
{
User = user,
Info = currentInfoEntry
}
我想使用 FullName 进行全文搜索。有没有比将查询转换为 SQL 更简单的方法?
I'm trying to implement a full-text search with EntityFramework.
My DB has a table called Users and a table called UserInfoEntries. The table users is connected to some other tables, and the table UserInfoEntries contains user information.
When i want to get the user info, i go through the entries in User.UserInfoEntries
and get the one with the oldest entry timestamp.
The property i want to use as the key for the full-text search is the FullName property within the UserInfoEntry.
The LINQ for getting the users with the exact FullName looks like this:
from user in objectContext.Users
let currentInfoEntry =
(from entry in user.UserInfoEntries
orderby entry.EntryTimestamp descending
select entry
).FirstOrDefault()
where currentInfoEntry.FullName == "Some Name"
select new UserWithInfo
{
User = user,
Info = currentInfoEntry
}
I would like to use the full-text search by FullName. Is there an easier way than transalting the query to SQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是全文搜索。这只是一个完全匹配的普通搜索。您可以通过还原来简化查询:
此查询要求您的
UserInfoEntry
实体具有名为User
的导航属性,该属性指向User
实体。This is not full-text search. It is just a normal search with the full match. You can simplify the query by reverting it:
This query expects that your
UserInfoEntry
entity has navigation property calledUser
pointing toUser
entity.