【发布时间】:2019-09-17 07:25:21
【问题描述】:
如何将List<Person> personList 转换为DBDataReader?
在下面给出的代码中,我尝试批量插入personList。我有大约 500k 条记录,WriteToServer 方法需要一个 DBDataReader,而我有一个 List<Person>。如何将List<Person> 转换为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;}
【问题讨论】:
-
可能是this?乍一看,我看到它甚至提到了批量复制。
标签: c# entity-framework sqlbulkcopy dbdatareader