在.net core 2.2中创建了新项目并安装了nuget软件包linq2db.sqlserver,使用此软件包,我能够使用数据库优先方法进行CRUD,但我需要知道如何使用代码优先方法进行CRUD。
Linq2Db具有链接https://linq2db.github.io/index.html其中提供了有关如何创建POCO以及基于POCO创建表的更多信息。
根据页面,一个简单的POCO可以像这样:
using System;
using LinqToDB.Mapping;
[Table(Name = "Products")]
public class Product
{
[PrimaryKey, Identity]
public int ProductID { get; set; }
[Column(Name = "ProductName"), NotNull]
public string Name { get; set; }
// ... other columns ...
}
然后您需要配置连接字符串。