I have a three tier system, SQL Server backend, hand written data access layer, and using stored procedures.
I have a table called EventTable. Each row is an ‘Event’. An Event has a primary key, and a start date.
CREATE TABLE EventTable
(
ID INT IDENTITY(100,1) PRIMARY KEY,
StartTime DateTime NOT NULL
)
There is a stored procedure called EventTable_Create. Incidentally, is the create method okay as written?
CREATE PROCEDURE Event_Create
@NewID INT OUT
AS
DECLARE @START DATETIME
SELECT @START = getdate()
INSERT INTO EventTable VALUES(@START, NULL)
SELECT @NewID = MAX(ID) FROM EventTable
GO
The data access layer returns an int to the caller, but should it instead return an instance of a data transfer object called Event? If that is true, should I be returning both the newly created ID and start time as well, so that the data access layer can create the event transfer object?
It all depends on what you need in your domain layer via data access. Since you are creating this by passing the information from domain layer, I ma assuming you already have most of the event information in your domain logic. In that case, all you need is an ID to populate it as part of your event object if you have one.
So it all depends on what you need in your domain layer and for what reasons.