小编dim*_*ath的帖子

更新拥有的实体 EF Core 5

我正在使用 .net 5 实现一个 api。我有一个学生类,它有一个地址类型的属性(根据 ddd 的值对象)。

public class Student 
{
        public long Id{ get; private set; }
        public string FirstName { get; private set; }
        public string LastName { get; private set; }
        public Address Address { get; private set; }
}

public class Address
{
    public string City { get; private set; }
    public string Road { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 fluent api 使用 ef core 5 配置数据库。

 class StudentConfiguration : IEntityTypeConfiguration<Student>
    {

        public void Configure(EntityTypeBuilder<Student> …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core .net-core asp.net-core

3
推荐指数
1
解决办法
337
查看次数

使用 fluent api EF Core 5 的多对多关系

我想我有两个具有多对多关系的实体,我将使用 fluent api 来解决这种关系

public class Author
{
    public int AuthorId { get; set; }
    public string Name { get; set; }
    public ICollection<Book> Books { get; set; }
}

public class Book
{
    public int BookId { get; set; }
    public string Title { get; set; }
    public ICollection<Author> Authors { get; set; }
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{  
   //Book
    modelBuilder.Entity<Book>().HasKey(x => x.BookId);
    modelBuilder.Entity<Book>().Property(x => x.Title).IsRequired();

    //Author
    modelBuilder.Entity<Author>().HasKey(x => x.AuthorId);
    modelBuilder.Entity<Author>().Property(x => x.Name).IsRequired();

    //many to many relationship …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core entity-framework-core-5

2
推荐指数
1
解决办法
1548
查看次数

ConfigurationManager错误:通用类型'configurationmanager &lt;T&gt;'需要1个类型参数

我在Visual Studio 2017中创建了一个新的项目空白Web应用程序。然后,我使用sqlserver创建数据库,并尝试使用dapper。我写了一个方法我在行中出错

 using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
        {
            return Ok(db.Query<Employee>
            ("Select * From ergaz").ToList());
        }
Run Code Online (Sandbox Code Playgroud)

我创建了一个web.config gile来放置代码

  <connectionStrings>
<add name="myConnectionString" connectionString="Data Source=aaaaaaa\SQLEXPRESS;Initial Catalog=APIDB;Integrated Security=True;" />
Run Code Online (Sandbox Code Playgroud)

但ConfigurationManager一词带有红色下划线并表示

使用通用类型'configurationmanager T'需要1个类型参数

我已经使用了System.Configuration。我搜索在解决方案中添加程序集引用,但是当我尝试添加它时,弹出窗口为空。 屏幕截图

c# dapper .net-core

0
推荐指数
1
解决办法
515
查看次数