简体   繁体   English

linq查询对象列表中的多列

[英]linq query on multiple columns from a list of objects

I have a list of configuration objects which contains three fields: type, minvalue and maxvalue. 我有一个配置对象列表,其中包含三个字段:类型,最小值和最大值。 I also have a campaign table and its configuration are stored in the configuration table. 我也有一个活动表,其配置存储在配置表中。 Campaign configuration table contains four columns: type, minvalue, maxvalue and campaignid. 广告系列配置表包含四列:类型,最小值,最大值和campaignid。 I want to join the list of configuration from the user with the configuration table to select the most appropriate campaign? 我想将用户的配置列表与配置表一起选择最合适的广告系列? Can anyone let me know how to do this using linq ? 谁能让我知道如何使用linq执行此操作?

Domain Entity Models:

public class Configuration
{
    public int Type { get; set; }       

    public string Value { get; set; }

    public string ValueMax { get; set; }    

    public Campaign Campaign { get; set; }        
}

public class Campaign
{
    public long Id { get; set; }
    public ICollection<Configuration> Configuration { get; set; }
}

Client Request Models:

public class FiltersVM
{
    public int type { get; set; }
    public string Value { get; set; }
    public string ValueMax { get; set; }
}

public class FilterRequest
{ 
    public List<FiltersVM>  Filters { get; set; }
}

I need a list of campaign Id's which exactly match the configurations like 1, 2, 3 我需要一个与1、2、3等配置完全匹配的广告系列ID列表

OK, so what you want is to find which Campaigns have a specific configuration, right? 好的,所以您要查找哪些广告系列具有特定的配置,对吗? You could select all configurations that satisfy your query and then navigate to its Campaign. 您可以选择满足查询条件的所有配置,然后导航至其Campaign。

Configuration.Where(c=> c.Type == type && Value == value && ValueMax == valueMax).Select(c=> c.Campaign.Id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM