[英]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.