首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解决LiteDB实现错误?

如何解决LiteDB实现错误?
EN

Stack Overflow用户
提问于 2020-04-26 05:24:32
回答 1查看 309关注 0票数 1

我是C#的新手。我正在尝试在.Net Core3.1中设置用于博客的LiteDB。

代码语言:javascript
复制
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”)得到错误;说: error CS0266:不能隐式地将类型'LiteDB.ILiteCollection‘转换为'LiteDB.LiteCollection’。存在显式转换(是否缺少强制转换?)(CS0266)

我的Model.cs文件:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
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; }
}
}

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-26 06:27:44

试试这个:

代码语言:javascript
复制
public ILiteCollection<Post> Posts { get; set; }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61432819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档