How to disable entity framework from creating Nullable property's

Is there a way to disable or to stop the entity framework from creating Nullable properties in complex class?

Example, when I add a new stored procedure to the entity framework it generates a class like the one below.

    //------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace StorefrontSystemDL
{
    using System;

    public partial class proc_InsertLeafHorizontal_Result
    {
        public Nullable<int> SizeID { get; set; }
        public Nullable<int> FinishID { get; set; }
        public Nullable<int> SitelineID { get; set; }
    }
}

How can i, do i, or is there a settings that i can set to where the entity framework does not create properties with Nullable types

Below is a snap shot of the source columns.

Source Not Null

For my stored procedure here is the body of the tsql

    AS
BEGIN
SET NOCOUNT ON;

 BEGIN TRAN
   BEGIN TRY
EXEC Storefront.proc_InsertHorizontal @Position,@Name,@Floor,@IsFiller,
                                      @WidthInches,@HeightInches,@WidthPercent,@HeightPercent,
                                      @DayliteWidthInches,@DayliteHeightInches,
                                      @Finish,@FinishNote,@FinishType,@FinishName,
                                      @ComponentID,@Note,
                                      @HorizontalID OUT;
    IF(@HorizontalID IS NOT NULL)
     INSERT INTO [StorefrontSystem].[Storefront].[LeafHorizontal]
           ([LeafID]
           ,[HorizontalID])
     VALUES
           (@LeafID,
            @HorizontalID)
----
SELECT h.SizeID,h.FinishID,h.SitelineID FROM Storefront.Horizontal h WHERE h.ID = @HorizontalID;
COMMIT TRAN
END TRY
 BEGIN CATCH
   ROLLBACK TRAN;
 END CATCH
SET NOCOUNT OFF;
END;

Upvotes: 3

Views: 3698

Answers (1)

Cornel Marian
Cornel Marian

Reputation: 2503

1) Save designer file and generate your database from designer 2) Click on Context file and Code Generation file(T4) and click run custom tool. 3) Make sure you save the file again, an * will appear after you generate the database.

or How to set entity framework 4.5 to never set any property as Nullable

Upvotes: 1

Related Questions