我编写了一个SQL SP来在MSSQL表中插入记录
CREATE PROCEDURE AddAmazonIT
@BatchID INT,
@ITName NVARCHAR(MAX)
AS
BEGIN
INSERT INTO tbl_AmazonITMaster
(Batch_Id,IT_Name)
VALUES
(@BatchID,@ITName)
SELECT @@IDENTITY
END
我有大约15000条记录要插入DB,
我使用企业库ExecuteScalar方法调用SP ...
插入数据时需要花费很多时间
C#Object Manager类如下:
public class BaseRepository
{
private string _key = "SqlDatabase";
public SqlDatabase Db
{
get {
if (ContextRepository.GetData(_key) == null)
{
ContextRepository.SetData(_key, DatabaseFactory.CreateDatabase());
}
return (SqlDatabase)ContextRepository.GetData(_key);
}
}
public SqlConnection Con
{
get {
return new SqlConnection(ConfigurationManager.ConnectionStrings["PTMap"].ConnectionString);
}
}
}
public class AmazonITRepository:BaseRepository
{
public int Add(AmazonIT it)
{
return Convert.ToInt32(Db.ExecuteScalar("AddAmazonIT", it.Batch_Id, it.IT_Name));
}
}
关于如何优化这个的任何想法?