如何通过.NET CORE 2.2中的代码优先方法使用linq2db在Microsoft SQL Server中创建数据库 [英] How to create database in Microsoft SQL Server using linq2db by code first approach in .NET CORE 2.2
问题描述
在.net core 2.2中创建了新项目,并使用该软件包安装了nuget软件包 linq2db.sqlserver ,我能够使用数据库优先方法进行CRUD,但是我需要知道如何首先使用代码来进行CRUD方法.
Created new project in .net core 2.2 and installed nuget package linq2db.sqlserver using this package i am able to do CRUD with database first approach but i need to know how to do CRUD using code first approach.
推荐答案
Linq2Db具有链接 https://linq2db.github.io/index.html 其中提供了有关如何创建POCO以及基于POCO创建表的更多信息.
Linq2Db has a link https://linq2db.github.io/index.html which provides more information about how to create a POCO and create a table based on it.
根据页面,一个简单的POCO可以像这样:
As per the page, a simple POCO can go like this:
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 ...
}
然后,您需要配置连接字符串.
Then you need to configure the connection strings.
这篇关于如何通过.NET CORE 2.2中的代码优先方法使用linq2db在Microsoft SQL Server中创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!