c# - 如何在 .NET CORE 2.2 中通过代码优先方法使用 linq2db 在 Microsoft SQL Server 中创建数据库
问题描述
在 .net core 2.2 中创建了新项目并使用此包安装了 nuget 包linq2db.sqlserver我能够使用数据库优先方法进行 CRUD,但我需要知道如何使用代码优先方法进行 CRUD。
解决方案
Linq2Db 有一个链接https://linq2db.github.io/index.html ,它提供了有关如何创建 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 ...
}
然后您需要配置连接字符串。
推荐阅读
- jwt - 访问令牌的定制算法
- java - PlantUML java自动化
- php - 用户'root'@'localhost'的访问被拒绝)
- angular - 如何从 Web Api 获取单个十进制值并使用 httpClient 在 Angular 10 中显示它
- pycharm - 解决 PyCharm 中的 git 冲突
- node.js - 如何使用 or 和 like 运算符在 express 中查询 mongodb
- java - 将动态膨胀视图添加到 2 个父视图
- docker - Docker-Desktop-Data 不会响应
- android - Flutter 卡住加载 Webview
- python - 用日期时间格式减去字符串格式的日期时间