data-access-layer

How do I determine if a column is in the primary key of its table? (SQL Server)

家住魔仙堡 提交于 2019-12-18 11:48:04
问题 I am currently using... select Table_Name, Column_name, data_type, is_Nullable from information_Schema.Columns ...to determine information about columns in a given database for the purposes of generating a DataAccess Layer. From where can I retrieve information about if these columns are participants in the primary key of their table? 回答1: Here is one way (replace 'keycol' with the column name you are searching for): SELECT K.TABLE_NAME , K.COLUMN_NAME , K.CONSTRAINT_NAME FROM INFORMATION

What is the difference between DAO and DAL?

天涯浪子 提交于 2019-12-18 10:05:23
问题 Having studied Java at school I am quite familiar with the DAO-pattern(Data access object). However at work I use .NET. In .NET there is often talk about the DAL(Data Access Layer). To me their purpose seems quite similar. So the question is are DAO and DAL basically the same thing? Is the term DAL only made up so it wouldn't be mixed up with Data Access Objects? 回答1: The Data Access Layer (DAL) is the layer of a system that exists between the business logic layer and the persistence /

One complex query vs Multiple simple queries

房东的猫 提交于 2019-12-18 04:33:26
问题 What is actually better? Having classes with complex queries responsible to load for instance nested objects? Or classes with simple queries responsible to load simple objects? With complex queries you have to go less to database but the class will have more responsibility. Or simple queries where you will need to go more to database. In this case however each class will be responsible for loading one type of object. The situation I'm in is that loaded objects will be sent to a Flex

How does the MVC pattern differ, if at all, from the DAL / BLL design pattern?

拥有回忆 提交于 2019-12-18 02:46:51
问题 I'm making my way through the early Data Access Tutorials on Microsoft's ASP.NET website and it occurred to me that this all seems awfully similar to what I have read about separating your logic and presentation code using the MVC pattern. As a newbie I have yet to implement the MVC pattern but I'm curious as to how these two design structures differ and if I should be focusing my attention on one or the other, particularly in the context of web design. 回答1: The link you've posted for the

How to write unit tests for database calls

和自甴很熟 提交于 2019-12-17 23:36:53
问题 I'm near the beginning of a new project and (gasp!) for the first time ever I'm trying to include unit tests in a project of mine. I'm having trouble devising some of the unit tests themselves. I have a few methods which have been easy enough to test (pass in two values and check for an expected output). I've got other parts of the code which are doing more complex things like running queries against the database and I'm not sure how to test them. public DataTable ExecuteQuery(SqlConnection

In separate data access & business logic layer, can I use Entity framework classes in business layer?

余生长醉 提交于 2019-12-17 22:42:19
问题 In separate data access & business logic layer, can I use Entity framework classes in business layer? EDIT: I don't think I will need to swap out the data access layer from my business logic in the future (i.e. will be SQL Server), however I will for the UI layer. Therefore the question is more meant to be are there any major issues with using EF classes for me in the business layer? Seems like there would be less plumbing code. 回答1: Typically, the "best practice" approach would be something

Are long-living transactions acceptable?

三世轮回 提交于 2019-12-17 20:59:57
问题 I am thinking about using transactions in 2-tier WPF (or windows forms) applications in following way: We can begin new transaction when we open new form for editing data, edit and persist changes transparently in this transaction. Then we can click "OK" button and commit transaction, or "Cancel" button and rollback it. If we want to open another dialog window with this data, we can use nested transactions. The question is: Is this way of using transactions acceptable or not? I know that

Entity Framework - layered design - Where to put connectionstring?

南笙酒味 提交于 2019-12-17 18:41:49
问题 I am using a layered architecture with the Entity Framework as my datalayer with a bunch of repositories on top which contain the Linq-To-Entities queries. The data layer is one project, next to that I have a Services layer and the interface, which is a website. I want my website to be responsible of specifying the connectionstring for my entity model. How do I do this? I am using a singleton method to get to my entity repository, which is located inside the datalayer. Thanks 回答1: You can

What is the purpose of a Data Access Layer? [closed]

送分小仙女□ 提交于 2019-12-17 15:48:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I started a project a long time ago and created a Data Access Layer project in my solution but have never developed anything in it. What is the purpose of a data access layer? Are there any good sources that I could learn more about the Data Access Layer? 回答1: In two words: Loose Coupling To keep the code you use

Improve data access layer select method Pattern

≯℡__Kan透↙ 提交于 2019-12-17 15:41:55
问题 Lately I find myself writing data access layer select methods where the code all takes this general form: public static DataTable GetSomeData( ... arguments) { string sql = " ... sql string here: often it's just a stored procedure name ... "; DataTable result = new DataTable(); // GetOpenConnection() is a private method in the class: // it manages the connection string and returns an open and ready connection using (SqlConnection cn = GetOpenConnection()) using (SqlCommand cmd = new