如何解决 LiteDB 执行错误?

How to solve LiteDB implementation error?

我是 C# 新手。我正在尝试在 .Net Core 3.1 中为博客设置 LiteDB。

namespace Blog.Repos
{
public class BlogRepo
  {
    public LiteDatabase DB { get; set; }
    public LiteCollection<Post> Posts { get; set; }

    public BlogRepo()
    {
        DB = new LiteDatabase(@"Data/Blog.db");
        Posts = DB.GetCollection<Post>("posts"); //Error
    }
  }
}

在 VS 中,我在 Posts = DB.GetCollection("posts") 处遇到错误;说:错误 CS0266:无法将类型 'LiteDB.ILiteCollection' 隐式转换为 'LiteDB.LiteCollection'。存在显式转换(是否缺少转换?)(CS0266)

我的 Model.cs 文件:

namespace case4ms.Models
{
   public class Model
{
    // Everything needs and ID, not explanation required
    public string ID { get; set; }

    // Will hold the original creation date of the field, 
    // the default value is set to DateTime.Now
    public DateTime Created { get; set; } = DateTime.Now;

    // will hold the last updated date of the field
    ///will initially be set to DateTime.Now, but should be updated on every...update
    public DateTime Updated { get; set; } = DateTime.Now;
    public bool Deleted { get; set; } = false;
}

}

和Post.cs文件:

namespace case4ms.Models
{
public class Post:Model
{
    public string Title { get; set; }
    public int Views { get; set; } = 0;
    public string Content { get; set; }
    public string Excerpt { get; set; }
    public string CoverImagePath { get; set; }
    public bool Public { get; set; }
}
}

我做错了什么?

试试这个:

public ILiteCollection<Post> Posts { get; set; }