enkodellc / blazorboilerplate

Blazor Boilerplate / Starter Template with MudBlazor
MIT License
1.87k stars 372 forks source link

Test Breeze.Sharp #554

Closed agorota closed 3 years ago

agorota commented 3 years ago

Hi, I'm trying Breeze.Sharp starting from the ToDo example, I created a new table manually in the default database BlazorBoilerplate:

New Table: [Customer]

I created ICustomer in BlazorBoilerplate.Shared.DataInterfaces

public interface ICustomer { Guid customer_id {get; set; } String customer {get; set; } String description {get; set; } }

I created the Customer class in BlazorBoilerplate.Shared.Dto.Db

**public partial class Customer: BaseEntity, ICustomer { public Guid customer_id { get {return GetValue (); } set {SetValue (value); } }

    public String customer
    {
        get {return GetValue <String> (); }
        set {SetValue (value); }
    }

    public String description
    {
        get {return GetValue <String> (); }
        set {SetValue (value); }
    }
}**

I added in IApiClient BlazorBoilerplate.Shared.Interfaces

Task <QueryResult > GetCustomers ();

I added in BlazorBoilerplate.Shared.Services ApiClient.cs public async Task <QueryResult > GetCustomers () { return await GetItems (from: "Customer", orderByDescending: i => i.customer); }

After that I doubled the TodoList.razor by modifying it appropriately for the new table ...

but I can't get data in var result = await apiClient.GetCustomers ();

Do I need anything else to consume data with Breeze.Sharp?

Thanks

GioviQ commented 3 years ago

To create breeze sharp entities and interfaces run https://github.com/enkodellc/blazorboilerplate/tree/master/src/Utils/BlazorBoilerplate.EntityGenerator

GioviQ commented 3 years ago

Also you don't have to create tables manually in db, you have to use EF migrations. https://blazor-boilerplate.readthedocs.io/en/latest/quickstarts/entity_framework_core.html

agorota commented 3 years ago

If I have to manage a new table why should I migrate? Migrations from what? I do not understand... to manage a new table with Breeze could you tell me the basic steps to follow?

Thank you

GioviQ commented 3 years ago

Migration is the process to update database with changes you made to Entity Framework entities. So you do not have to manually update db. Steps: Create new EF entity Update db with a migration Run Generator to create the new Breeze entity

agorota commented 3 years ago

Where should I create new EF entity?

GioviQ commented 3 years ago

In https://github.com/enkodellc/blazorboilerplate/tree/master/src/Shared/BlazorBoilerplate.Infrastructure.Storage/DataModels

agorota commented 3 years ago

Thanks, I've made some progress ... created EF entity as follows:

**namespace BlazorBoilerplate.Infrastructure.Storage.DataModels { [Permissions (Actions.Delete)] public partial class Todotest: IAuditable, ISoftDelete { [Key] public long Id {get; set; }

     [Required (ErrorMessage = "FieldRequired")]
     [MaxLength (128)]
     public string Title {get; set; }

     public bool IsCompleted {get; set; }
 }

}**

At this point I ran both the migration and the run generetor. It created me tables and related code. By loading the clone of the ToDo razor page appropriately referenced on the new table I can update new rows but it does not populate the list on the screen. i just get it displays the following error:

"Unexpected character encountered while parsing value: <. Path '', line 0, position 0."

in "var result = await apiClient.GetToDoTests ();"

agorota commented 3 years ago

Now works, was missing in ApplicationController this:

[AllowAnonymous] [HttpGet] public IQueryable Todotests() { return persistenceManager.GetEntities().Include(i => i.CreatedBy).Include(i => i.ModifiedBy).OrderBy(i => i.Id); }

great job this BlazorBoilerPlate with Breeze.Sharp And thanks for the assistance!