具有多个后端和不同数据库设计的数据访问层(Data Access Layer with Multiple Backends and Different Database Designs)
我正在开始一个项目,并且正在为我们的数据访问层而苦苦挣扎。 基本上它需要与不同数据库设计的多个后端接口。
我想要一个通用的DAL,然后在任何后端执行一个通用功能。 后端具有用于插入,更新等的唯一代码。因此,在1个后端中添加一个Employee将在另一个代码中具有不同的代码。
我尝试了Repository模式,但这并不适用于这种情况。 我已经结束了一个工厂模式的方法,但我最终会为每个对象创建一个工厂。 我可能只能创建1个工厂,但后端对象将具有数百个函数,如“SaveEmployee”,“SavePlan”等。
现在我有以下几点:
DAL --> DAL.Backend1 --> Employee.Save(employee) --> Plan.Save(plan) --> DAL.Backend2 --> Employee.Save(employee) --> Plan.Save(plan)
在DAL项目中,我为每个对象,员工,计划都有一个工厂模式,以决定返回并执行哪个DAL对象。
我很确定这不是最好的架构,所以我想知道是否有更好的模式来解决我的问题。
I am starting a project and am struggling with the architecture for our data access layer. Basically it will need to interface with multiple backends with different database designs.
I would like a common DAL, which then executes a common function in any backend. The backends have unique code for inserting, updating, etc. So adding an Employee in 1 backend will have different code in another.
I tried the Repository pattern but that just doesn't apply to the situation. I've ended up with just a Factory pattern method, but I will end up creating a Factory for each object. I could maybe only create 1 factory but then the Backend object would have hundred of functions like "SaveEmployee", "SavePlan", etc.
Right now I have the following:
DAL --> DAL.Backend1 --> Employee.Save(employee) --> Plan.Save(plan) --> DAL.Backend2 --> Employee.Save(employee) --> Plan.Save(plan)
In the DAL project I have a Factory pattern for each Object, Employee, Plan, to decide which DAL's Object to return and execute against.
I am pretty sure this is not the best architecture for this, so I am wondering if there's a better pattern to use to solve my problem.
原文:https://stackoverflow.com/questions/14508077
最满意答案
你可以使用这样的循环:
char northl2[100] = {0}; northl2[0]='1'; northl2[1]='1'; int count_one = 0; for (int i = 0;i<100;++i) { if (northl2[i] == '1') { ++count_one; } } std::cout << count_one;
在这种情况下,这打印2,因为有2
1
。 代码遍历数组的每个元素,检查它的值,并递增其计数。char northl2[100] = {0};
默认情况下将每个元素设置为0.如果需要不同的值,请使用循环:char northl2[100]; int main() { int count_one = 0; for (int i = 0; i< 100;++i) { northl2[i] = 'C'; //Or whatever char other than '1' } northl2[0]='1'; northl2[1]='1'; for (int i = 0;i<100;++i) { if (northl2[i] == '1') { ++count_one; } } }
另外,不要忘记在循环为所有元素赋值后分配1,否则它们将被覆盖 。
You could use a loop like this:
char northl2[100] = {0}; northl2[0]='1'; northl2[1]='1'; int count_one = 0; for (int i = 0;i<100;++i) { if (northl2[i] == '1') { ++count_one; } } std::cout << count_one;
This prints 2 in this case, because there are 2
1
's. The code iterates through each element of the arrays, checks it for a value, and increments its count. Thechar northl2[100] = {0};
sets by-default each element to 0. If you need a different value, use a loop:char northl2[100]; int main() { int count_one = 0; for (int i = 0; i< 100;++i) { northl2[i] = 'C'; //Or whatever char other than '1' } northl2[0]='1'; northl2[1]='1'; for (int i = 0;i<100;++i) { if (northl2[i] == '1') { ++count_one; } } }
Also, don't forget to assign the 1's after the loop assigns values to all of the elements, or else, they will be overwritten.
相关问答
更多-
我假设listLeft是你的ListView。 你需要添加这样的子项目: foreach (DirectoryInfo directory in directories) { ListViewItem lvi = new ListViewItem(); lvi.SubItems.Add("Directory " + directory.Name); listLeft ...
-
尝试这个: $_SESSION['basket'][] = $_POST['item']; 如果您的数组使用数字索引,则比使用array_push更有效。 Try this: $_SESSION['basket'][] = $_POST['item']; If your array uses numeric index, is more efficiently than use of array_push.
-
您找到的答案是针对Winforms的,您似乎正在使用WPF。 它们都有一个ComboBox控件,但它们实际上是一个具有不同属性的完全不同的控件。 试试这个(假设你称之为ComboBox1 ): ComboBox1.ItemsSource = myList; 但是,您通常需要商品的ID,以便在用户选择商品时使用它们。 为此,您需要将ComboBox绑定到Dictionary而不是List ,如下所示: var data = new Dictionary
{ {1 ... -
如何将项添加到android中的自定义数组列表[关闭](How to add items to the custom array list in android [closed])[2022-11-22]
这样做 Listcategories = new ArrayList (); while(c.moveToNext()){ categoryName = c.getString(c.getColumnIndex("CategoryName")); Categories categoryObject=new Categories(); categoryObject.CategoryName=categoryName; categories.a ... -
数组重新分配C ++(array reallocation C++)[2022-02-13]
旧的数组items只有size元素,因此当您将旧元素复制到新数组时,需要将for循环的上限从size*2更改为size 。 Your old array items has only size elements, so you need to change the upper limit in your for loop to size from size*2 when you're copying the old elements to the new array. -
您可以使用$ setIntersection运算符轻松实现第二个输出。 db.users.aggregate( [ {$match:{"_id": 507c35dd8fada716c89d0013}}, { $project: { "watching": { $setIntersection: [ "$watchlist", [ 342, 999, 8745 ] ] } } } ] ) You can easily achieve the second output using $s ...
-
你可以使用这样的循环: char northl2[100] = {0}; northl2[0]='1'; northl2[1]='1'; int count_one = 0; for (int i = 0;i<100;++i) { if (northl2[i] == '1') { ++count_one; } } std::cout << count_one; 在这种情况下,这打印2,因为有2 1 。 代码遍历数组的每个元素,检查它的值,并递增其计数。 char ...
-
在Stack Overflow PHP Chat中讨论之后 ,发现的问题如下: $ignore数组的结构奇怪,如果一个学生有多个会议,它会创建多个顶级数组,而它应该只使用一个引用该特定学生的数组。 in_array_r函数的结构不正确。 最终修复导致以下更改: 对于#1: $ignore数组的添加更改为: $ignore[$item["pupil_id"]][] = array("meeting_id" => $item2["meeting_id"], "endTime" => $item2["endTim ...
-
没有NS等效于ABRecordRef和ABRecordRef -containsObject:只需在其所有对象上调用-isEqual:以确定是否已包含重复项,因此您的方法无法正常工作。 我建议围绕ABRecordRef编写一个包装类,并在ABRecordRef实现自己的-isEqual:方法。 更新: 正如@omz所指出的,它确实有效,因为CFEqual()被调用了,谢谢! 但是,在ABRecordRef周围使用包装类仍然是一个好主意。 There is no NS-equivalent to ABReco ...
-
这不是问题的答案,因为它目前正在制定(akonsu已经在他的评论中回答了问题的标题),也没有直接谈论这个问题。 然而,既然我明白她想要完成什么(并且她对其他方法持开放态度),我认为这基本上是一个非常好的问题, 所以我发布这个是为了帮助其他人理解她真正希望用她发布的代码完成什么,并帮助她更详细地定义算法变化和最终结果/输出可能/应该是什么。 她希望在y数(上一行所在的针迹)上尽可能均匀地均匀分布x数(每行额外针数)。 img http://i48.tinypic.com/1fxp21.gif 她目前的基本公式 ...