我正在为一个果园项目的新模块工作。我们建立了与地址部分相关联的公司部分。我最终试图让用户通过ui(非管理界面)输入各种搜索条件,对所有公司进行搜索并返回任何匹配的结果。
我在努力解决的问题是如何构建允许我从相关地址中包含信息的查询。到目前为止,我只能根据CompanyPartRecord而不是CompanyPart成功返回结果。 CompanyPartRecord显然只包含相关AddressPart的Address_Id。
本质上,我试图找到这样的东西,这将返回与输入的搜索条件匹配的可枚举或公司列表。除了zip之外还有更多的搜索选项,所以我正在寻找可扩展的解决方案。
var query = _companyRepository.Table.AsQueryable();
if (!string.IsNullOrEmpty(Zip))
query = query.Where(c => c.Address.Zip == Zip);
var queryResult = query.ToList();
我尝试过使用IRepository(如上所示)和IContentManager,如下所示:
var query = _contentManager.Query<CompanyPart, CompanyPartRecord>();
//var query = _contentManager.Query<CompanyPart>();
if (!string.IsNullOrEmpty(Zip))
query = query.Where(c => c.Address.Zip == Zip);
var queryResult = query.ToList();
这是实际的公司和地址(部件和记录):
public class CompanyPartRecord : ContentPartRecord
{
public virtual string Name { get; set; }
public virtual string Description { get; set; }
public virtual int Address_Id { get; set; }
public virtual string Phone { get; set; }
public virtual string OtherInformation { get; set; }
public virtual string Website { get; set; }
public virtual bool Inactive { get; set; }
// Keywords - Taxonomy
// Logo - associated part
// HasMissingData - derived
// NumberOfEmployees - associated part
}
public class CompanyPart : ContentPart<CompanyPartRecord>, ITitleAspect
{
internal readonly LazyField<AddressPart> AddressField = new LazyField<AddressPart>();
public string Name
{
get { return Record.Name; }
set { Record.Name = value; }
}
public string Description
{
get { return Record.Description; }
set { Record.Description = value; }
}
public AddressPart Address
{
get { return AddressField.Value; }
set { AddressField.Value = value; }
}
public string Phone
{
get { return Record.Phone; }
set { Record.Phone = value; }
}
public string OtherInformation
{
get { return Record.OtherInformation; }
set { Record.OtherInformation = value; }
}
public string Website
{
get { return Record.Website; }
set { Record.Website = value; }
}
public bool Inactive
{
get { return Record.Inactive; }
set { Record.Inactive = value; }
}
public string Title
{
get { return Name; }
}
}
public class AddressPartRecord : ContentPartRecord
{
public virtual string Street { get; set; }
public virtual string Street2 { get; set; }
public virtual string City { get; set; }
public virtual string CountyName { get; set; }
public virtual NationRecord State { get; set; }
public virtual string Zip { get; set; }
}
public class AddressPart : ContentPart<AddressPartRecord>
{
public string Street
{
get { return Record.Street; }
set { Record.Street = value; }
}
public string Street2
{
get { return Record.Street2; }
set { Record.Street2 = value; }
}
public string City
{
get { return Record.City; }
set { Record.City = value; }
}
public string CountyName
{
get { return Record.CountyName; }
set { Record.CountyName = value; }
}
public NationRecord State
{
get { return Record.State; }
set { Record.State = value; }
}
public string Zip
{
get { return Record.Zip; }
set { Record.Zip = value; }
}
}
答案 0 :(得分:0)
我假设你有一个包含两个部分的内容类型(即名为 Company ),如果是这样的话应该有效:
var query = _contentManager.Query("Company").Where<AddressPartRecord>(x => x.Street == "query street");
var list = query.ToList();
该列表包含按街道过滤的ContentItems。在列表项上使用.As()和.As()可以访问每个部分。