C# 如何使实体框架6使用SQL序列中的默认值
我创建了以下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
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; }