标签:img generic constrain ati arch red table clust nbsp
我们先在数据库中建立一个Book表:
CREATE TABLE [dbo].[Book]( [ID] [int] IDENTITY(1,1) NOT NULL, [BookName] [nvarchar](50) NULL, [BookDescription] [nvarchar](50) NULL, [ISBN] [nvarchar](20) NULL, [CreateTime] [datetime] NULL, CONSTRAINT [PK_Book] 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 [dbo].[Book] ADD CONSTRAINT [DF_Book_CreateTime] DEFAULT (getdate()) FOR [CreateTime] GO
然后插入如下数据:
INSERT [dbo].[Book] ([BookName], [BookDescription], [ISBN]) VALUES (N‘Chinese‘, N‘Chinese‘, N‘0001‘) GO INSERT [dbo].[Book] ([BookName], [BookDescription], [ISBN]) VALUES (N‘English‘, N‘English‘, N‘0002‘) GO INSERT [dbo].[Book] ([BookName], [BookDescription], [ISBN]) VALUES (N‘Japanese‘, N‘Japanese‘, N‘0003‘) GO INSERT [dbo].[Book] ([BookName], [BookDescription], [ISBN]) VALUES (N‘Russian‘, N‘Russian‘, N‘0004‘) GO INSERT [dbo].[Book] ([BookName], [BookDescription], [ISBN]) VALUES (N‘Italian‘, N‘Italian‘, N‘0005‘) GO
查询Book表的数据,如下图所示:
现在我们使用EF Core将Book表映射到.NET Core控制台项目中的Book实体上,Book实体如下所示:
using System; using System.Collections.Generic; namespace EFCoreDB.Entities { public partial class Book { public int Id { get; set; } public string BookName { get; set; } public string BookDescription { get; set; } public string Isbn { get; set; } public DateTime? CreateTime { get; set; } } }
EF Core 2.0中开启Transaction事务会对DbContext创建和关闭数据库连接的行为有所影响
标签:img generic constrain ati arch red table clust nbsp
原文地址:https://www.cnblogs.com/OpenCoder/p/9803032.html