data-access-layer

C# Handle on SQL Server Message Output [duplicate]

别来无恙 提交于 2019-12-01 00:47:09
问题 This question already has answers here : Capture Stored Procedure print output in .NET (3 answers) Closed 3 years ago . When executing scripts in SQL Server Management Studio, messages are often generated that display in the message window. For example when running a backup of a database: 10 percent processed. 20 percent processed. Etc... Processed 1722608 pages for database 'Sample', file 'Sampe' on file 1. 100 percent processed. Processed 1 pages for database 'Sample', file 'Sample_Log' on

NHibernate removes DAL?

删除回忆录丶 提交于 2019-11-30 18:10:41
问题 Am I right that using NHibernate (or any other ORM) removes the necessity of DAL? Or not? 回答1: You need a DAL, the question is what do you do in the DAL. In a .NET project with NHibernate, I use this organisation MyProject.Core.DomainModel : in this project only the .cs and mapping files (.hbm.xml) MyProject.Repo : in this classes you use NHibernate method like Get, Load, make query .... MyProject.Service : from these classes, I call the MyProject.Repo methods MuProject.UI : ASP.NET, ASP.NET

What's the difference between DAO and Data Mapper

一世执手 提交于 2019-11-30 15:55:04
问题 Is there a difference between the DAO pattern and the Data Mapper pattern? Is DAO just one of doing Data Mapper? 回答1: I wouldn't actually call DAO a "pattern". As I see it, DAO is pretty much what it is -- a Data Access Object", which encapsulates the details of accessing a persistent data store and generally speaking has nothing to do with the database: interface IBlogDaoService { Blog GetBlog(long id); void SaveBlog(Blog blog); } It's clear that implementations can use either DB (in which

What's the difference between DAO and Data Mapper

拈花ヽ惹草 提交于 2019-11-30 15:30:29
Is there a difference between the DAO pattern and the Data Mapper pattern? Is DAO just one of doing Data Mapper? I wouldn't actually call DAO a "pattern". As I see it, DAO is pretty much what it is -- a Data Access Object", which encapsulates the details of accessing a persistent data store and generally speaking has nothing to do with the database: interface IBlogDaoService { Blog GetBlog(long id); void SaveBlog(Blog blog); } It's clear that implementations can use either DB (in which case it's quite logical to use a Data Mapper), or simple XML file storage mechanism. The Data Mapper on the

Ways of unit testing data access layer

依然范特西╮ 提交于 2019-11-30 12:42:13
问题 I have be trying to look for an effective way in unit testing my data access layer in C#. I'm primary a Java developer and have only used C# for about 6 months, in the past i've used a library called DBUnit to test against a known state database. I haven't been able to find a similar active library that can be used, closest seems to be nDBUnit but it hasn't been active for awhile now. There seems to be a lot of conflicting methods on how and why in C#. Ideally I want to test the data access

Execute stored procedure w/parameters in Dapper

一个人想着一个人 提交于 2019-11-30 11:22:47
I'm using Dapper (thanks Sam , great project.) a micro ORM with a DAL and by some reason I'm not able to execute stored procedures with input parameters. In a example service I've the following code: public void GetSomething(int somethingId) { IRepository<Something, SomethingEnum> repository = UnitOfWork.GetRepository<Something, SomethingEnum>(); var param = new DynamicParameters(); param.Add("@somethingId", dbType: DbType.Int32, value:somethingId, direction: ParameterDirection.Input); var result = repository.Exec<Something>(SomethingEnum.spMyStoredProcedure, param); ... } When the execution

Mocking vs. Test DB?

£可爱£侵袭症+ 提交于 2019-11-30 08:10:25
Earlier I asked this question How to correctly unit test my DAL? , one thing left unanswered for me is if to really test my DAL is to have a Test DB, then what is the role of mocking vs. a testing DB? To add on this, another person suggested to "use transactions and rollback at the end of the unit test, so the db is clean", test db that is. What do you guys think of this testing + test DB + transaction rollback (so db is not really written) approach to test DAL? To be complete, my DAL is built with Entity Framework, there is no stored proc in DB. Since EF is so new, I really need to test DAL

No context type was found in the assembly

纵饮孤独 提交于 2019-11-30 07:53:54
I'm using .NET 4.0, MVC3, and EF5 with code first. My solution is split up into three projects, with the dependencies as indicated: Project.Web -> Project.BLL -> Project.DAL The Project.DAL layer contains my entity framework data context class and all my entities, but my startup project is Project.Web, so it contains my Web.config, connection strings, and the actual SQL compact database. I'm trying to enable migrations so I can add a new table to my EF model without wiping the existing data. However, when I run "Enable-Migrations", I get No context type was found in the assembly 'Project.Web'.

What is the best practice for multiple “Include”-s in Entity Framework?

核能气质少年 提交于 2019-11-30 06:48:40
Let's say we have four entities in data model: Categories, Books, Authors and BookPages. Also assume Categories-Books, Books-Authors and Books-BookPages relationships are one-to-many. If a category entity instance is retrieved from database - including "Books", "Books.BookPages" and "Books.Authors" - this will become a serious performance issue. Moreover, not including them will result in "Object reference is not set to an instance of an object" exception. What is the best practice for using multiple Include method calls? Write a single method GetCategoryById and include all items inside

Do you allow the Web Tier to access the DAL directly?

梦想与她 提交于 2019-11-30 06:22:20
问题 I'm interested in perceived "best practice", tempered with a little dose of reality here. In a web application, do you allow your web tier to directly access the DAL, or should it go through a BLL first? I'm talking specifically of scenarios where there's no "business logic" really involved -- such as a simple query : "Fetch all customers with surname of 'Atwood'". Scenarios where there's any kind of logic absolutely are gonna go through the BLL, so lets call that moo. While you could