I have a database (PostgreSQL) from which I want to migrate some data to a MS SQL Server database. I decided to use a code first approach. The question is related to the proper way of feeding my new tables.
Model.cs:
public class Info
{
[Key]
public int InfoID { get; set; }
public int NameID { get; set; }
public string Name { get; set; }
}
DatabaseInitializer:
private void SeedInfos(SomeContext context)
{
var Infos = new List<Info>();
using (var com = new NpgsqlCommand(PostgresSQLs.GetAllInfos, EstablishedConnection()))
{
using (var r = com.ExecuteReader())
{
while (r.Read())
{
Infos.Add(new Info { InfoID= Convert.ToInt32(r["infoID"]), NameID = Convert.ToInt32(r["NameId"]), Name = r["Name"].ToString()});
};
}
}
foreach (var Usr in Users)
context.Infos.Add(Usr);
}
One of my concerns is related to the static class PostgreSQL
where I store queries which are retrieving the data I need from PostgreSQL. Is it a proper approach? The more complicated query, the more complex code, so it may be hard to maintain later, isn't it? What approach would you use?
Besides, such data feeding may cost a lot of memory in case the table is big. Is there a possibility to avoid memory leaks?
PostgresSQLs
class? Right now your question is kinda blurry. \$\endgroup\$