S
S
Sergey Melnikov2022-01-11 16:05:32
ASP.NET
Sergey Melnikov, 2022-01-11 16:05:32

How to make a settings table mapping?

Hi all.
Can you tell me how to implement a mapping in a model with a settings table in an Asp.net project?
Example - there is a table User
Id, Name
and a table Settings
Id, Param, Value, UserId Plz direct me
where to dig. To get the associated settings for that user from the User model.

I think that you need to have Settings, for example, such a

class Settings {

protected string Param1 { get; set;}
protected string Param2 {get; set;}

}

class User {

protected string Name {get; set;}
protected Settings Settings {get; set;}

}
And how to work from the User model with different parameters associated only with this user?
Maybe this is a pattern, and does it have a name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2022-01-11
@firedragon

Dig towards the Code First approach.
Let EF Core have a headache.
And by the way, your structure is only suitable for hardwired parameters.
But if you need to change it from the application, you will have to recompile.
I would recommend the following db structure
id kkey kval userId
or if the db supports json
id json userId
Each approach has its pros and cons
link to ef core
https://docs.microsoft.com/ru-ru/aspnet/core/data/. ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question