Reputation: 1122
Assume that a desktop app communicates some data with a server, it storage them, and a web client can access the data via SQL queries.
In past, there was EntityFramework models that were shared by MVC web app project and C# WPF project so that I didn't care about things with database.
But now I have one .Net Core web app whose server side is C# and client side is React+Redux, and have one desktop app built with Electron+React+Redux.
I suppose I need to create one set of models for the server side and the corresponding one for client/desktop app, but am not sure if it's okay to create two functionally identical set of the models.
Is there any good resource or comment regarding how to deal with this topic?
Upvotes: 1
Views: 270
Reputation: 2967
You have to return JSON result from your controller action methods. If there is no difference in the model of database and View you can reuse the same models. But the best practice is to separate out your View Models from your entity models. To do this transitions you can use auto mapper on the server side.
React can easily understand your JSON results and can accordingly bind it to your UI.
Same even with your WPF (which is desktop client). I can also invoke your Controller actions and get the JSON results and populate the UI accordingly.
Here is a simple example for React one.
Upvotes: 1