简体   繁体   English

如何禁用实体框架来创建Nullable属性

[英]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? 有没有办法禁用或阻止实体框架在复杂类中创建Nullable属性?

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 我如何,或者我是否可以设置实体框架不会使用Nullable类型创建属性的设置

Below is a snap shot of the source columns. 下面是源列的快照。

来源不是空的

For my stored procedure here is the body of the tsql 对于我的存储过程,这里是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;

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. 1)保存设计器文件并从设计器生成数据库2)单击上下文文件和代码生成文件(T4),然后单击运行自定义工具。 3) Make sure you save the file again, an * will appear after you generate the database. 3)确保再次保存文件,生成数据库后将出现*。

or How to set entity framework 4.5 to never set any property as Nullable 或者如何将实体框架4.5设置为永不将任何属性设置为Nullable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查实体框架类型的属性是否可为空 - How to check if a property of an Entity Framework type is Nullable 使用LINQ连接可为空的属性时,如何防止Entity Framework添加ISNULL检查 - How to prevent Entity Framework from adding ISNULL checks when joining on a nullable property with LINQ 如何将实体框架4.5设置为永不将任何属性设置为Nullable - How to set entity framework 4.5 to never set any property as Nullable 实体框架不可为空的列映射到可为空的实体属性 - Entity Framework Non-nullable column is mapped to a nullable entity property 实体框架中不可为空的导航属性为null - Non nullable navigation property is null in Entity Framework 在实体框架中以编程方式获取属性的“空”状态 - Get the 'Nullable' state programmatically of a Property in Entity Framework 实体框架使双精度为可空属性 - Entity Framework making double a nullable property 如何在实体框架中从可为空的关系中选择非可为空 - How to select non nullables from nullable relation in Entity Framework 处理 Net 6 的可为空和实体框架实体 - Deal with in Net 6's nullable and Entity Framework entities 使用Entity Framework 6创建计算属性 - Creating a computed property with Entity Framework 6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM