How can I Convert a List<Person> personList
to DBDataReader
?
In the code that I have given below, I am trying to bulk insert personList
. I have around 500k records, and the method WriteToServer
expects a DBDataReader and I have a List<Person>
. How can I convert List<Person>
to DBDataReader
using (SqlBulkCopy bc= new SqlBulkCopy(constr)) {
bc.DestinationTableName = "MyPersonTable";
try
{
bc.WriteToServer(personList);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}\
\
**Person Model**
public int personId {get;set;} // Primarykey
public string personName {get;set;}
public int personAge {get;set;}
public DateTime personCreatedDate {get;set;}
you can use this one and after that with SqlBulkCopy insert all data to database: