如何通过.NET CORE 2.2中的代码优先方法使用linq2db在Microsoft SQL Server中创建数据库

问题描述 投票:0回答:1

在.net core 2.2中创建了新项目并安装了nuget软件包linq2db.sqlserver,使用此软件包,我能够使用数据库优先方法进行CRUD,但我需要知道如何使用代码优先方法进行CRUD。

c# sql .net asp.net-core-2.2 linq2db
1个回答
0
投票

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 ...
}

然后您需要配置连接字符串。

© www.soinside.com 2019 - 2024. All rights reserved.