EF Core Data Binding from a Blazor WebAssembly Project

I am creating a Blazor WebAssembly App, backed by CosmosDB and using EF Core for Data Access using this method.

The examples I've seen for using EF as as a Data Adaptor using the Web Api controller as a middleman for the requests.

Does anyone know what the best way to bind data from EF Core in a Standalone Blazor WebAssembly App? Would I need to write a custom adaptor?

Any help would be greatly appreciated 😅

Adriaan

3 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team July 17, 2020 02:44 PM UTC

Hi Adriaan, 

Greetings from Syncfusion. 

We have validated your query and you have told that you have already configured Blazor Webassembly application with CosmosDB and using EF core. You can use either implemented way or you can write a CustomAdaptor for consuming the data. You can any of those way to bind the data. 

If you want to create a CustomAdaptor for binding the data, then find the below documentation for your reference. 

Reference: 

// Implementing custom adaptor by extending the DataAdaptor class 
    public class CustomAdaptor : DataAdaptor 
    { 
        // Performs data Read operation 
        public override object Read(DataManagerRequest dm, string key = null) 
        { 
            IEnumerable<MyEntity> DataSource = await _client.GetJsonAsync<List<MyEntity>>("/api/entity/get"); 
            if (dm.Search != null && dm.Search.Count > 0) 
            { 
                // Searching 
                DataSource = DataOperations.PerformSearching(DataSource, dm.Search); 
            } 
            . . . 
            if (dm.Take != 0) 
            { 
                DataSource = DataOperations.PerformTake(DataSource, dm.Take); 
            } 
            return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;   //return data as Result and Count pair for binding the data to Grid 
        } 
    } 


Please get back to us if you need further assistance. 

Regards, 
Rahul 


Marked as answer

AV Adriaan van der Bergh July 18, 2020 07:47 AM UTC

Hi Rahul,

Thank you for the response. I am in the process of trying to use a custom data binding, but it is a lot of code to write.

Could you please explain a little more what you meant by using the "implemented way" ?

Are you referring to the method explained in this article? Because from I understand, this is only possible on a Blazor Hosted App with an API endpoint? Since I am creating a Standalone Blazor Webassembly App, I am not able to register an API endpoint.

Or is there another Implemented Way that does not require an API endpoint?

Kind Regards,
Adriaan



RN Rahul Narayanasamy Syncfusion Team July 22, 2020 09:07 AM UTC

Hi Adriaan, 
 
Query: Or is there another Implemented Way that does not require an API endpoint? 
 
We have validated your query and the Blazor application will run in same security sandbox as JavaScript and it cannot access files from disk or databases directly. Hence API endpoint is the only way to access entity framework dbcontext. 
 
Please let us know if you have any other concerns. 
 
Regards, 
Rahul 
 


Loader.
Up arrow icon