为什么我们使用实体框架时 SQL 中的默认值未注册?
T-SQL中的表代码:
CREATE TABLE [dbo].[T2](
[ID] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](50) COLLATE Arabic_CI_AS NOT NULL,
[Groups] [int] NOT NULL CONSTRAINT [DF_T2_Groups] DEFAULT (ident_current('T2')),
CONSTRAINT [PK_T2] 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]
Groups
当我使用实体框架时,无法注册该列的默认值。
为什么?
解决办法是什么?
班级
public class T2
{
public int ID { set; get; }
public string name { set; get; }
public int Groups { set; get; }
}
telentity db = new telentity();
db.T2.Add(new T2()
{
name="ali"
});
db.SaveChange();