views:

29

answers:

0

I'm using sqlmetal.exe to generate a DataContext class from a sqlserver database to use with LINQ. I have a bunch of stored procedures that in some cases returns a primary key column that is a NOT NULL INT, such as this one:

CREATE PROCEDURE spDDIs_Find(@DDINumber VARCHAR(64)) AS

IF NOT EXISTS (SELECT ID FROM tDDIs WHERE DDINumber = @DDINumber)
    RAISERROR('ICT0015:DDI not found.', 18, 1)

ELSE
            // D.ID is a primary key NOT NULL INT column
    SELECT TOP 1 D.ID, D.SchemeID, D.ConfigurationID, C.Description Configuration,
           D.RecordCall, D.DDINumber
      FROM tDDIs D
      LEFT JOIN tConfigurations C ON C.ID = D.ConfigurationID
     WHERE D.DDINumber = @DDINumber

But the code generated by sqlmetal.exe sets the column type to System.Nullable, like this:

public partial class spDDIs_FindResult
{       
    private System.Nullable<int> _ID;               //wrong
    private System.Nullable<int> _SchemeID;         //wrong
    private System.Nullable<int> _ConfigurationID;  //wrong
    private string _Configuration;      
    private System.Nullable<bool> _RecordCall;      //wrong
    private string _DDINumber;
    ...

As I'm in the development process working on the database with other members of the team working on the .NET data layer, I need to continually regenerate the DataContext code as the database gets updated, so modifying the code manually and setting the wrongly marked Nullables to a normal int isn't an option because I'd be forever editing the code.

Is there a way to re-work my stored proc so that sqlmetal picks up the NOT NULL columns correctly?

Thanks, Ben