Im storing a huge amount of data in JSON format that needs to be committed to DB.
This JSON data is being deserialized into a C# class[].
Thing is there are other seed data thats stored in a static readonly Class[]
and simply being loaded/sent to DB.
My question is which is better assuming we have 20k records for an entity. Having a JSON and deserializing or having a huge static readonly class[]
?
My objective is to have a single uniform method of storing data instead of different types of files for the same thing.
Edit: My question apparently wasn't well explained so Ill use an example this time. I have 2 options to load data: a Json:
[
{
Id: "56d0bdbe-25be-4ea8-a422-dc302deee962",
Name: "C-1"
LegacyId: 1
},
{
Id: "7bf2e997-8a8b-43c9-ba08-1770cd3adb38",
Name: "C-2"
LegacyId: 2
}
]
Each item is being deserialized into a UserEntity
which is then later stored in db.
However there are other files that are being used for the same purpose of loading data to db. But in this case they are stored like this:
public static class UserSeedData
{
public static readonly UserEntity[] UserData = {
new UserEntity{
Id = "56d0bdbe-25be-4ea8-a422-dc302deee962",
Name = "C-1",
LegacyId = 1
},
new UserEntity{
Id = "7bf2e997-8a8b-43c9-ba08-1770cd3adb38",
Name = "C-2",
LegacyId = 2
}
};
}
My question is which is faster or if theres a difference at all between loading and serializing the JSON // loading the static class UserSeedData
to insert it on DB.
Im focusing on the deserialization part and not the committing to DB. This is a legacy system which is currently using BOTH ways to load data. Im simply trying to normalize the process by defining which method is better.
In the end the code to commit to DB is either:
From JSON:
List<UserEntity> users = JsonConvert.DeserializeObject<List<UserEntity>>(File.ReadAllText("Users.json"));
foreach (var userData in users)
{
_db.Add(userData);
}
Or from C# class:
foreach (var userData in UserSeedData.UserData)
{
_db.Add(userData);
}