添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have created a project using .Net Core, Blazor, and LiteDB.

There are a few articles out there which reference using LiteDB with core so I don't think there is an issue there.

Here is my code.

<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;

As you can see all I want to do here is to return the amount of Groups that exist in my collection. I can confirm there are records in the collection in the database.

No matter what I try it always returns 0. I'm brand new (just started learning today) with Blazor, and equally as new with core. I've used LiteDB on a similar project.

To be honest I'm not sure if i'm even making a connection with my LiteDB. I have tried to insert into the db but that also does nothing. Which would point me to an issue with the connection string, but I've just copied the path from the .db file and used that.

Any suggestions?

Never heard of LiteDB ! The question Is whether it is supported on Blazor... Did you try to use the same code on the server. Create a simple web application in Asp.Net Core and see how it works... – enet Dec 31, 2018 at 8:48 Is this a straight Blazor app or is it server-side (Net Components)? Because if this is Blazor in the browser, there's no way it can go and find your database. That would require filesystem access and all kinds of unpleasantness. If you really need a database in the browser, try using Chanan's BlazorDB, on nuget and here - github.com/chanan/BlazorDB – Rich Bryant Dec 31, 2018 at 8:59 @RichBryant That makes complete sense. Totally overlooked that somehow. Thanks for the input. Switching to a server side model did fix the issue. Also thank you for the suggestion with BlazorDB. – Night Channels Jan 1, 2019 at 19:12

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.