public int Insert<T>(IReadOnlyCollection<T> models)
where T : class, new()
{
int sucess = 0;
if (models.Count > 0)
{
foreach (var model in models)
{
string name = model.GetType().Name;
if (name.Equals("TempInfo"))
{
TempInfo temp = (TempInfo)(object)model;
sucess = InsertUser(temp);
}
}
}
return sucess;
}
private int InsertUser(TempInfo temp)
{
int sucess = 0;
using (EFEntity ef = new EFEntity())
{
ef.TempInfo.Add(temp);
sucess = ef.SaveChanges();
}
return sucess;
}
int sucess = 0;
EFEntity entity = new EFEntity();
InsertOprater oprator = new InsertOprater();
IReadOnlyCollection<TempInfo> list = new Collection<TempInfo>() {
new TempInfo(){
Name = "123",
Age = 1,
Address = "沈阳市",
Phone = "13578907890",
condition = "测试"
},
new TempInfo(){
Name = "1234",
Age = 2,
Address = "沈阳市吧",
Phone = "13012345678",
condition = "测试2"
},
new TempInfo(){
Name = "12345",
Age = 3,
Address = "本溪市",
Phone = "13409876543",
condition = "测试3"
}
};
sucess = oprator.Insert(list);
if (sucess > 0)
{
MessageBox.Show("添加数据模块成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("添加数据模块失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}