首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >数据库体系结构问题

数据库体系结构问题
EN

Stack Overflow用户
提问于 2019-05-20 04:30:48
回答 1查看 0关注 0票数 0

我有一个SQL数据库,一旦构建,我将通过LINQ与之交互。它有一个客户端(忽略其他人)两个表的两个fkID字段。

类 国家

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

代码语言:javascript
复制
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

因此,这是在规则表中执行此操作的最佳方法

RuleID Identity ClassFK Int null CountryFK Int null order int not null

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

代码语言:javascript
复制
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
     }
}

这对我来说似乎非常脆弱

EN

Stack Overflow用户

发布于 2019-05-20 13:53:08

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

代码语言:javascript
复制
foreach(rule in rules.Where(r => r.AppliesTo(client)))
{
    // Create the Rows
}

但是,我看到缺少的部分是根据特定规则知道要创建的行; 这不包含在您的规则表中。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100001160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档