3
Vote

Get One generated code throws SqlException

description

After running the Get One recipe, the generated code compiles fine but there is an error when executing Get One operations.
 
This issue is related to the Get One changes to use the new ISimpleDomainObjectFactory interface. It seems that the Get One stored procedures need to be changed to specify OUT or IN/OUT parameters for each parameter that would otherwise have been columns in the cursor. See [workitem:32194].
 
This issue was identified using the Test Plan: http://www.codeplex.com/RepositoryFactory/Wiki/View.aspx?title=TestPlan
 
STEPS
 
  1. Download and install the test database (SQL Server version) from: http://www.codeplex.com/ChinookDatabase/Release/ProjectReleases.aspx
     
  2. Create the CRUD stored procedures by running the from the attached file. At the Command Prompt window, run:
    osql -E -S .\sqlexpress -d Chinook -i StoredProcedures.sql
     
  3. Open the VS2005 solution from the attached file, build it and run the unit tests.
     
     
    RESULTS
     
    Running unit test of test plan results in:
     
    System.Data.SqlClient.SqlException: Procedure or Function 'GetAlbumByAlbumId' expects parameter '@albumId', which was not supplied.
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
    at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
    at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteNonQuery(DbCommand command)
    at Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteNonQuery(DbCommand command)
    at Microsoft.Practices.Repository.Repository1.FindOne<TIdentity>(ISelectionFactory1 selectionFactory, ISimpleDomainObjectFactory`1 domainObjectFactory, TIdentity identity)
    at DataAccess.AlbumRepositoryArtifacts.AlbumRepository.GetAlbumByAlbumId(Int32 albumId) in AlbumRepository.cs: line 56
    Microsoft.Practices.Repository.RepositoryFailureException: Unexpected error occurred in the database server
    at DataAccess.AlbumRepositoryArtifacts.AlbumRepository.HandleSqlException(SqlException ex, IDbToBusinessEntityNameMapper mapper) in AlbumRepository.cs: line 124
    at DataAccess.AlbumRepositoryArtifacts.AlbumRepository.GetAlbumByAlbumId(Int32 albumId) in AlbumRepository.cs: line 60
    at RepositoryFactoryTestApp.Tests.RepositoryTests.Album_CRUD() in RepositoryTests.cs: line 68

file attachments

comments

GurdeepToor wrote Jun 2, 2009 at 4:02 PM

I am having this issue with all my Get one methods.. Any one has the solution for this ? My code looks like
    Dim AM As AddressModel = New AddressModel()
    AM = GRH.AddressModelRepository.GetSpikeAddressModelByID(22)
    Me.txtName.Text = AM.FullAdressLabel
I am getting Runtime Error

{"Procedure or function 'GetSpikeAddressModelByID' expects parameter '@iD', which was not supplied."}

My Repository classes seems to be OK. The Mapping code for GetByID method looks like

public string MapDbParameterToBusinessEntityProperty(string dbParameter)
    {
        switch (dbParameter)
        {
            case "iD":
                return "iD";
            default:
                throw new RepositoryInvalidParameterException(dbParameter);
        }
    }
What I am doing wrong ??

GurdeepToor wrote Jun 2, 2009 at 4:02 PM

I am having this issue with all my Get one methods.. Any one has the solution for this ? My code looks like
    Dim AM As AddressModel = New AddressModel()
    AM = GRH.AddressModelRepository.GetSpikeAddressModelByID(22)
    Me.txtName.Text = AM.FullAdressLabel
I am getting Runtime Error

{"Procedure or function 'GetSpikeAddressModelByID' expects parameter '@iD', which was not supplied."}

My Repository classes seems to be OK. The Mapping code for GetByID method looks like

public string MapDbParameterToBusinessEntityProperty(string dbParameter)
    {
        switch (dbParameter)
        {
            case "iD":
                return "iD";
            default:
                throw new RepositoryInvalidParameterException(dbParameter);
        }
    }
What I am doing wrong ??

wrote Jun 2, 2009 at 4:08 PM

wrote Jul 14, 2009 at 2:36 PM

sdathathraya wrote Nov 24, 2009 at 2:38 AM

Here is what i did to get around this issue.

Use the GetMany recipe to generate the code. Map the same stored procedure that returns a single record. The result of this operation is a list of items.

The list contains a single element.

Didn't have the time to debug and fix the recipe.

sdathathraya wrote Nov 24, 2009 at 2:40 AM

Here is what i did to get around this issue.

Use the GetMany recipe to generate the code. Map the same stored procedure that returns a single record. The result of this operation is a list of items.

The list contains a single element.

Didn't have the time to debug and fix the recipe.

wrote Feb 14, 2013 at 3:27 AM