我有三个实体:
public class KeywordSearch
{
// Primary properties
public int Id { get; set; }
public string Name { get; set; }
// Navigation properties
public Keyword Keyword { get; set; }
}
public class Keyword
{
// Primary properties
public int Id { get; set; }
public string Name { get; set; }
// Navigation properties
public virtual ICollection<Address> Addresses { get; set; }
}
public class Address
{
// Primary properties
public int Id { get; set; }
public PTCouncil PTCouncil { get; set; } <---------- EDIT
// Navigation properties
public virtual ICollection<Keyword> Keywords { get; set; }
}
public class PTCouncil <---------- EDIT
{
// Primary properties
public int Id { get; set; }
public string Name { get; set; }
}根据一组单词,我需要提取所有不同的地址Id。
将在KeywordSearch表中搜索与地址相关的匹配关键字的单词。
到目前为止,在William的帮助下,我做到了这一点,但是获取匹配所有和部分单词的关键字,并且我需要将它们全部获取:
编辑:
var addressIds = (
from ks in keywordSearchQuery
where splitKeywords.Contains(ks.Name)
select ks.Keyword.Addresses.Select(k => k.Id)
)
.ToList()
.Aggregate((a, b) => a.Intersect(b));示例:
KeywordSearch = {1,"RENAULT",1},{2,"MORAIS",2},{3,"SOARES",3},{4,"CENTRO",4}
Keyword = {1,"Renault",{1,2}},{2,"Morais",{1}},{3,"Soares",{1}},{4,"Centro",{2}}
Address = {1,"Renault Morais Soares",{1,2,3}},{2,"Renault Centro",{1,2}}
If I search "RENAULT MORAIS SOARES", I should get AddressId = 1
If I search "RENAULT CENTRO", I should get AddressId = 2
If I search "RENAULT", I should get AddressId = 1,2
Actual Search Problem: If I search "RENAULT XXXX", I get 1,2 and I should get nothing.我还需要按位置过滤,我已经尝试过了,但我得到了一个错误“指定的类型成员'PTCouncil‘在LINQ to Entities中不受支持”
keywordsAddressIds = from ks in keywordSearchQuery
where splitKeywords.Contains(ks.Name)
select ks.Keyword.Addresses.Where(p => p.Location.Distance(centerPoint) < radius * 1000).Select(a => a.Id);有什么想法吗?
谢谢。
发布于 2013-12-05 13:14:59
我认为您应该尝试使用inner join,它也用于从许多表获取数据
Select TABLE1.Field1,TABLE1.Field2,TABLE2.Field1 from TABLE1 INNER JOIN TABLE2 on TABLE1.Field1=TABLE2.Field1
https://stackoverflow.com/questions/20127755
复制相似问题