代码之家  ›  专栏  ›  技术社区  ›  MarkKGreenway

数据库体系结构问题

  •  0
  • MarkKGreenway  · 技术社区  · 15 年前

    我有一个SQL数据库,一旦构建好,我将通过LINQ与之交互。 它有一个客户机,该客户机将两个FKID字段(忽略其他字段)放在两个表中。

    等级
    国家

    我要做的是存储一个“规则”表,其中会发生以下情况:

    if the Class is 'A' and the Country is 'USA' then 
        create rows  'RowsA' in table todo
    
    else if the class is 'A' and the country is not 'USA' then
        create rows 'RowsB'  in table todo
    
    else
        create rows 'RowsC' in table todo
    



    所以,在规则表中这样做的最好方法是

    规则标识
    类FINK 无效的
    CountryFK int空
    秩序 不为空


    并让我的C代码执行以下操作:

    var rules = from r in db.Rules
                orderby r.order
                select r;
    
    foreach(rule in rules)
    {
         if (((client.ClassFK == rule.ClassFK) || (rule.ClassFK == null)) &&             
               ((client.CountryFK== rule.CountryFK) || (rule.CountryFK== null)))
         {
              // Create The Rows
         }
    }
    

    我觉得这个很脆弱

    1 回复  |  直到 15 年前
        1
  •  1
  •   Chris Shaffer    15 年前

    我认为让它看起来更干净的一种方法是在规则类上创建一个方法,检查它是否应用于客户端;这使您的代码看起来像:

    foreach(rule in rules.Where(r => r.AppliesTo(client)))
    {
        // Create the Rows
    }
    

    但是,我看到的缺失部分是知道要基于特定规则创建哪些行;这不包含在规则表中。