首页 > 解决方案 > Blazor LiteDB 查询问题

问题描述

我使用 .Net Core、Blazor 和 LiteDB 创建了一个项目。

有几篇文章参考了使用带有核心的 LiteDB,所以我认为那里没有问题。

这是我的代码。

<p>@groups.Count()</p>

@functions{

//Collections
IEnumerable<Group> groups;

protected override void OnInit()
{
    string connectionString = "Path to my .db file";

    using (LiteDatabase db = new LiteDatabase(connectionString))
    {
        groups = db.GetCollection<Group>("Groups").FindAll();
    }
}

public class Group
{
    public int Id { get; set; }

    public string Name { get; set; }

    public string Description { get; set; }

    public bool Active { get; set; }

    public int XIndex { get; set; }

    public int YIndex { get; set; }

    public DateTime CreateDate { get; set; }

    public List<Task> Tasks { get; set; }

    public int RequestedBy { get; set; }

    public int CategoryId { get; set; }

    public int ProjectedCompletionMinutes { get; set; }

    public Group()
    {
        CreateDate = DateTime.UtcNow;
        Active = false;
        XIndex = 1;
        YIndex = 1;
    }
  }
}

如您所见,我在这里要做的就是返回我的集合中存在的组数量。我可以确认数据库中的集合中有记录。

无论我尝试什么,它总是返回 0。我是 Blazor 的新手(今天才开始学习),并且与核心一样新。我在一个类似的项目中使用过 LiteDB。

老实说,我不确定我是否与我的 LiteDB 建立了联系。我试图插入数据库,但这也没有任何作用。这会指出连接字符串的问题,但我刚刚从 .db 文件中复制了路径并使用了它。

有什么建议么?

标签: c#.net.net-coreblazorlitedb

解决方案


推荐阅读