Share via

Blazor Wasm mongoDB

Ningran Meng 21 Reputation points
2021-12-22T02:19:25.19+00:00

I am trying to do a tool management web assembly with Blazor and MongoDB. It's annoying to writing model for those collections that have exactly the same properties like name, description and so on.

Is it possible for me to only write one model, say cables? and use it to manipulate multiple cable collection in my MongoDB database? Do I need to write one model for each collection or I need to write only one model for cable?

I use the model -> repo --> controller structure for my backend, and razor component on my front-end.

Any feedback is welcomed.

This structure can be found at this url:

https://medium.com/@berkokur/creating-a-blazor-app-with-net-core-381e21793734

Developer technologies | .NET | Blazor

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 84,086 Reputation points
    2021-12-22T17:13:12.43+00:00

    using strong typed languages with MongoDb can be painful. But for performance, you should only return the data required for the query. MongoDB has a strong query language that is json based, and you strong control of the shape of the JSON response.

    if you are using strong typing with MongoDB you should define a model for each query response as using sparse objects can easily lead to bugs. you will probably use anonymous objects and an aggregation pipeline for updates and inserts.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.