How to create database in Microsoft SQL Server using linq2db by code first approach in .NET CORE 2.2

安稳与你 提交于 2020-01-22 02:31:13

问题


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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/59543993/how-to-create-database-in-microsoft-sql-server-using-linq2db-by-code-first-appro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!