How to get the data I want according to the rules : <p>I have a configuration table like the below, and some users with different attributes. I need to get a configuration data based on user attributes.</p>

<p>I don't know how to implement it, no idea.</p>

<p><a href="https://i.stack.imgur.com/vFKP3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vFKP3.png" alt="configuration data from db table"></a></p>

<p>Initial code: </p>

<pre><code>void Main()
{
    var configList = new List&lt;ConfigEntity&gt;() {
        new ConfigEntity { ConfigCode="37", GoodCode="A", UserType="personal", Country="US", State="NewYork", City="Buffalo", Price=37 },
        new ConfigEntity { ConfigCode="36", GoodCode="A", UserType="personal", Country="US", State="NewYork", City="Albany", Price=36 },
        new ConfigEntity { ConfigCode="35", GoodCode="A", UserType="personal", Country="US", State="NewYork", City="", Price=35 },
        new ConfigEntity { ConfigCode="34", GoodCode="A", UserType="personal", Country="US", State="", City="", Price=34 },
        new ConfigEntity { ConfigCode="40", GoodCode="A", UserType="personal", Country="China", State="Guangdong", City="Guangzhou", Price=40 },
        new ConfigEntity { ConfigCode="39", GoodCode="A", UserType="personal", Country="China", State="Guangdong", City="", Price=39 },
        new ConfigEntity { ConfigCode="38", GoodCode="A", UserType="personal", Country="China", State="", City="", Price=38 },
        new ConfigEntity { ConfigCode="33", GoodCode="A", UserType="personal", Country="", State="", City="", Price=33 },
        new ConfigEntity { ConfigCode="45", GoodCode="A", UserType="organization", Country="US", State="NewYork", City="Buffalo", Price=45 },
        new ConfigEntity { ConfigCode="44", GoodCode="A", UserType="organization", Country="US", State="NewYork", City="Albany", Price=44 },
        new ConfigEntity { ConfigCode="43", GoodCode="A", UserType="organization", Country="US", State="NewYork", City="", Price=43 },
        new ConfigEntity { ConfigCode="42", GoodCode="A", UserType="organization", Country="US", State="", City="", Price=42 },
        new ConfigEntity { ConfigCode="48", GoodCode="A", UserType="organization", Country="China", State="Guangdong", City="Guangzhou", Price=48 },
        new ConfigEntity { ConfigCode="47", GoodCode="A", UserType="organization", Country="China", State="Guangdong", City="", Price=47 },
        new ConfigEntity { ConfigCode="46", GoodCode="A", UserType="organization", Country="China", State="", City="", Price=46 },
        new ConfigEntity { ConfigCode="41", GoodCode="A", UserType="organization", Country="", State="", City="", Price=41 },
        new ConfigEntity { ConfigCode="29", GoodCode="A", UserType="", Country="US", State="NewYork", City="Buffalo", Price=29 },
        new ConfigEntity { ConfigCode="28", GoodCode="A", UserType="", Country="US", State="NewYork", City="Albany", Price=28 },
        new ConfigEntity { ConfigCode="27", GoodCode="A", UserType="", Country="US", State="NewYork", City="", Price=27 },
        new ConfigEntity { ConfigCode="26", GoodCode="A", UserType="", Country="US", State="", City="", Price=26 },
        new ConfigEntity { ConfigCode="32", GoodCode="A", UserType="", Country="China", State="Guangdong", City="Guangzhou", Price=32 },
        new ConfigEntity { ConfigCode="31", GoodCode="A", UserType="", Country="China", State="Guangdong", City="", Price=31 },
        new ConfigEntity { ConfigCode="30", GoodCode="A", UserType="", Country="China", State="", City="", Price=30 },
        new ConfigEntity { ConfigCode="25", GoodCode="A", UserType="", Country="", State="", City="", Price=25 },
        new ConfigEntity { ConfigCode="13", GoodCode="", UserType="personal", Country="US", State="NewYork", City="Buffalo", Price=13 },
        new ConfigEntity { ConfigCode="12", GoodCode="", UserType="personal", Country="US", State="NewYork", City="Albany", Price=12 },
        new ConfigEntity { ConfigCode="11", GoodCode="", UserType="personal", Country="US", State="NewYork", City="", Price=11 },
        new ConfigEntity { ConfigCode="10", GoodCode="", UserType="personal", Country="US", State="", City="", Price=10 },
        new ConfigEntity { ConfigCode="16", GoodCode="", UserType="personal", Country="China", State="Guangdong", City="Guangzhou", Price=16 },
        new ConfigEntity { ConfigCode="15", GoodCode="", UserType="personal", Country="China", State="Guangdong", City="", Price=15 },
        new ConfigEntity { ConfigCode="14", GoodCode="", UserType="personal", Country="China", State="", City="", Price=14 },
        new ConfigEntity { ConfigCode="9", GoodCode="", UserType="personal", Country="", State="", City="", Price=9 },
        new ConfigEntity { ConfigCode="21", GoodCode="", UserType="organization", Country="US", State="NewYork", City="Buffalo", Price=21 },
        new ConfigEntity { ConfigCode="20", GoodCode="", UserType="organization", Country="US", State="NewYork", City="Albany", Price=20 },
        new ConfigEntity { ConfigCode="19", GoodCode="", UserType="organization", Country="US", State="NewYork", City="", Price=19 },
        new ConfigEntity { ConfigCode="18", GoodCode="", UserType="organization", Country="US", State="", City="", Price=18 },
        new ConfigEntity { ConfigCode="24", GoodCode="", UserType="organization", Country="China", State="Guangdong", City="Guangzhou", Price=24 },
        new ConfigEntity { ConfigCode="23", GoodCode="", UserType="organization", Country="China", State="Guangdong", City="", Price=23 },
        new ConfigEntity { ConfigCode="22", GoodCode="", UserType="organization", Country="China", State="", City="", Price=22 },
        new ConfigEntity { ConfigCode="17", GoodCode="", UserType="organization", Country="", State="", City="", Price=17 },
        new ConfigEntity { ConfigCode="5", GoodCode="", UserType="", Country="US", State="NewYork", City="Buffalo", Price=5 },
        new ConfigEntity { ConfigCode="4", GoodCode="", UserType="", Country="US", State="NewYork", City="Albany", Price=4 },
        new ConfigEntity { ConfigCode="3", GoodCode="", UserType="", Country="US", State="NewYork", City="", Price=3 },
        new ConfigEntity { ConfigCode="2", GoodCode="", UserType="", Country="US", State="", City="", Price=2 },
        new ConfigEntity { ConfigCode="8", GoodCode="", UserType="", Country="China", State="Guangdong", City="Guangzhou", Price=8 },
        new ConfigEntity { ConfigCode="7", GoodCode="", UserType="", Country="China", State="Guangdong", City="", Price=7 },
        new ConfigEntity { ConfigCode="6", GoodCode="", UserType="", Country="China", State="", City="", Price=6 },
        new ConfigEntity { ConfigCode="1", GoodCode="", UserType="", Country="", State="", City="", Price=1 }
    };

    configList.Dump();

}

public class ConfigEntity
{
    public string ConfigCode { get; set; }
    public string GoodCode { get; set; }
    public string UserType { get; set; }
    public string Country { get; set; }
    public string State { get; set; }
    public string City { get; set; }
    public decimal Price { get; set; }
}
</code></pre>

<p>if GoodCode="A" and user (UserType="personal", Country="US", State="NewYork", City="Albany"), I expect get a data of ConfigCode="36";</p>

<p>if GoodCode="A" and user (UserType="personal", Country="China", State="Guangdong", City=""), I expect get a data of ConfigCode="39";</p>

<p>if GoodCode="A" and user (UserType="personal", Country="", State="", City=""), I expect get a data of ConfigCode="33";</p>

<p>if GoodCode="" and user (UserType="personal", Country="", State="", City=""), I expect get a data of ConfigCode="9";</p>

<p>if GoodCode="B" and user (UserType="", Country="", State="", City=""), I expect get a data of ConfigCode="1";</p>
