1

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?

Night Channels
  • 342
  • 1
  • 4
  • 12
  • 1
    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 '18 at 08:48
  • 2
    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 - https://github.com/chanan/BlazorDB – Rich Bryant Dec 31 '18 at 08:59
  • 1
    @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 01 '19 at 19:12

0 Answers0