我是C#的新手。我正在尝试在.Net Core3.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”)得到错误;说: error 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; }
}
}我做错了什么?
发布于 2020-04-26 06:27:44
试试这个:
public ILiteCollection<Post> Posts { get; set; }https://stackoverflow.com/questions/61432819
复制相似问题