data-access

Transactions for read-only DB access?

巧了我就是萌 提交于 2019-11-27 17:30:26
There seem to be very different opinions about using transactions for reading from a database. Quote from the DeveloperWorks article Transaction strategies: Models and strategies overview : Why would you need a transaction if you are only reading data? The answer is that you don't. Starting a transaction to perform a read-only operation adds to the overhead of the processing thread and can cause shared read locks on the database (depending on what type of database you are using and what the isolation level is set to). As a contrary opinion there is the following quote from Hibernate

What exactly is “persistence ignorance”?

做~自己de王妃 提交于 2019-11-27 12:20:42
Persistence ignorance is typically defined as the ability to persist & retrieve standard .NET objects (or POCOs if you really insist on giving them a name). And a seemingly well accepted definition of a standard .NET object is: "...ordinary classes where you focus on the business problem at hand without adding stuff for infrastructure-related reasons..." However, I see people describing NHibernate as a framework that allows persistence ignorance, and yet it is a framework that cannot work on any standard .NET object, only standard .NET objects that adhere to particular design requirements, for

How can I generate database tables from C# classes?

眉间皱痕 提交于 2019-11-27 10:23:40
Does anyone know a way to auto-generate database tables for a given class? I'm not looking for an entire persistence layer - I already have a data access solution I'm using, but I suddenly have to store a lot of information from a large number of classes and I really don't want to have to create all these tables by hand. For example, given the following class: class Foo { private string property1; public string Property1 { get { return property1; } set { property1 = value; } } private int property2; public int Property2 { get { return property2; } set { property2 = value; } } } I'd expect the

Can I have an optional OUTPUT parameter in a stored procedure?

坚强是说给别人听的谎言 提交于 2019-11-27 03:43:46
问题 I have a stored procedure that has a bunch of input and output parameters because it is Inserting values to multiple tables. In some cases the stored proc only inserts to a single table (depending on the input parameters). Here is a mocked up scenario to illustrate. Tables / Data Objects: Person Id Name Address Name Id FirstName LastName Address Id Country City Say I have a stored procedure that inserts a person. If the address doesn't exist I won't add it to the Address table in the database

Is it bad practice to run tests on a database instead of on fake repositories?

泄露秘密 提交于 2019-11-27 03:17:31
问题 I know what the advantages are and I use fake data when I am working with more complex systems. What if I am developing something simple and I can easily set up my environment in a real database and the data being accessed is so small that the access time is not a factor, and I am only running a few tests. Is it still important to create fake data or can I forget the extra coding and skip right to the real thing? When I said real database I do not mean a production database, I mean a test

Execute multiple SQL commands in one round trip

此生再无相见时 提交于 2019-11-26 20:20:29
问题 I am building an application and I want to batch multiple queries into a single round-trip to the database. For example, lets say a single page needs to display a list of users, a list of groups and a list of permissions. So I have stored procs (or just simple sql commands like "select * from Users"), and I want to execute three of them. However, to populate this one page I have to make 3 round trips. Now I could write a single stored proc ("getUsersTeamsAndPermissions") or execute a single

Transactions for read-only DB access?

自古美人都是妖i 提交于 2019-11-26 19:02:27
问题 There seem to be very different opinions about using transactions for reading from a database. Quote from the DeveloperWorks article Transaction strategies: Models and strategies overview: Why would you need a transaction if you are only reading data? The answer is that you don't. Starting a transaction to perform a read-only operation adds to the overhead of the processing thread and can cause shared read locks on the database (depending on what type of database you are using and what the