Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 相关实体(asp.net核心)上的筛选值_C#_Asp.net_Asp.net Mvc_Asp.net Core - Fatal编程技术网

C# 相关实体(asp.net核心)上的筛选值

C# 相关实体(asp.net核心)上的筛选值,c#,asp.net,asp.net-mvc,asp.net-core,C#,Asp.net,Asp.net Mvc,Asp.net Core,我有表属性,它们有相关的集合地址 这是模型 [Table("PM101Properties")] public class Property: FullAuditedEntity, IMustHaveTenant { [Required] public virtual Status Status { get; set; } public virtual int TenantId { get; set; }

我有表属性,它们有相关的集合地址

这是模型

 [Table("PM101Properties")]
    public class Property: FullAuditedEntity, IMustHaveTenant
    {        
        [Required]
        public virtual Status Status { get; set; }
        public virtual int TenantId { get; set; }
        public virtual int? LandlordId { get; set; }
        public virtual int? AgentId { get; set; }
        public virtual int PropertyTitleId { get; set; }
        public virtual int BuildingTypeId { get; set; }
        public virtual int PropertyTypeId { get; set; }
        [ForeignKey("LandlordId")]
        public virtual Landlord Landlord { get; set; }
        [ForeignKey("AgentId")]
        public virtual Agent Agent { get; set; }
        [ForeignKey("PropertyTitleId")]
        public virtual PropertyTitle PropertyTitle { get; set; }
        [ForeignKey("BuildingTypeId")]
        public virtual BuildingType BuildingType { get; set; }
        [ForeignKey("PropertyTypeId")]
        public virtual PropertyType PropertyType { get; set; }

        public virtual ICollection<PropertyAddress> Addresses { get; set; }
        public virtual ICollection<PM101Site> Sites { get; set; }
        public virtual ICollection<PropertyAsset> PropertyAssets { get; set; }
    }

如何筛选此属性?

PostCode是PropertyAddress的属性,您不能直接在地址集合中访问它。你必须迭代并抛出它

p.Addresses.Any(a => a.PostCode.Contains(input.Filter.Trim(), StringComparison.OrdinalIgnoreCase)

像这样使用“thenclude”:Include(x=>x.Addresses)。thenclude(addr=>addr.PostCode)我认为这不是个好主意。因为地址还具有Line1、Line2等属性。我需要搜索它们too@vhrif如果你想使用它们,你应该包括它们。有很多地址。包括。然后包括也许我们有更优雅的方法@vhrPostCode是一个实体,但也是第1行?在这种情况下,这听起来像是一个设计问题
 p.Addresses.PostCode.Contains(input.Filter.Trim(), StringComparison.OrdinalIgnoreCase)
p.Addresses.Any(a => a.PostCode.Contains(input.Filter.Trim(), StringComparison.OrdinalIgnoreCase)