Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使实体框架6使用SQL序列中的默认值_C#_Sql Server_Entity Framework_Entity Framework 6 - Fatal编程技术网

C# 如何使实体框架6使用SQL序列中的默认值

C# 如何使实体框架6使用SQL序列中的默认值,c#,sql-server,entity-framework,entity-framework-6,C#,Sql Server,Entity Framework,Entity Framework 6,我创建了以下SQL序列 CREATE SEQUENCE SEQ_ORDENES_TRABAJO as int START WITH 1 INCREMENT BY 1 MINVALUE 1 CYCLE ; 此表中使用的,用于允许“Concerutivo”字段使用该序列 CREATE TABLE [adm].[OrdenesTrabajo]( [Id] [uniqueidentifier] NOT NULL, [Consecutivo] [int] NOT NULL, [F

我创建了以下SQL序列

CREATE SEQUENCE SEQ_ORDENES_TRABAJO as int START WITH 1 INCREMENT BY 1 MINVALUE 1 CYCLE ;
此表中使用的,用于允许“Concerutivo”字段使用该序列

CREATE TABLE [adm].[OrdenesTrabajo](
    [Id] [uniqueidentifier] NOT NULL,
    [Consecutivo] [int] NOT NULL,
    [FechaIngreso] [datetime] NOT NULL,
    [RemolcadorId] [uniqueidentifier] NOT NULL,
    [Justificacion] [nvarchar](1000) NOT NULL,
    [Prioridad] [smallint] NOT NULL,
    [EstadoMantenimientoId] [uniqueidentifier] NOT NULL,
    [Usuario] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_adm.OrdenesTrabajo] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [adm].[OrdenesTrabajo] ADD  CONSTRAINT [OT_consecutivoConstraint]  DEFAULT (NEXT VALUE FOR [SEQ_ORDENES_TRABAJO]) FOR [Consecutivo]
GO
这是与该表匹配的实体框架类

[Table("adm.OrdenesTrabajo")]
public class OrdenTrabajo
{
    [Key]
    public Guid Id { get; set; }

    [Required]
    public Int32 Consecutivo { get; set; }

    [Required]
    public DateTime FechaIngreso { get; set; }

    [Required]
    public Guid RemolcadorId { get; set; }

    [Required]
    [MaxLength(1000)]
    public String Justificacion { get; set; }

    [Required]
    public Int16 Prioridad { get; set; }

    [Required]
    public Guid EstadoMantenimientoId { get; set; }

    [Required]
    public String Usuario { get; set; }

    [ForeignKey("RemolcadorId")]
    public Equipo Remolcador { get; set; }

    [ForeignKey("EstadoMantenimientoId")]
    public EstadoMantenimiento EstadoMantenimiento { get; set; }
}
当我使用的脚本在INSERT命令中省略了“CONCEDUTIVO”字段时,它会按预期工作,并从序列中获取值

如何使Entity Framework 6在插入实体时使用“ConcertiVO”列的默认值?


使用INSERT子句创建一个存储过程并从实体框架调用它,这是我唯一的选择吗?

事实证明,我需要的是一行指定它是一个
数据库生成的

    [Required]
    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public Int32 Consecutivo { get; set; }