I want to periodically copy large records from a SQL server into a in-memory table. I need to put these fields I read into my own objects, not into another SQL table or flat file storage. Is a SQLBulkCopy the way forward to do this?
create a class..
public class MemoryObject
{
public Int64 Id {get; set;}
public string OtherProperty {get; set;}
}
then, use a SQLDataReader...
public List<MemoryObject> GetMemoryObjects()
{
using (SqlConnection connection = new SqlConnection("..."))
{
string sql = "query";
SqlCommand command = new SqlCommand(sql.ToString(), connection);
command.CommandTimeout = 3600;
connection.Open();
var memoryObjects = new List<MemoryObject>();
using (var rdr = command.ExecuteReader())
{
while (rdr.Read())
{
var memoryObject = new MemoryObject {
Id = rdr.GetInt64(0),
OtherProperty = rdr.GetString(1)
};
memoryObjects.Add(memoryObject);
}
}
}
return memoryObjects;
}