???????????MVC + EF ??????У??????????????????DbContext?????????п??????MVC+EF??????????????????????????????????????????????????С????????и??????????????????????????
????1????????????飺??ADO.NET?У?????????????????д????SqlHelper????????£?????????????????????????????????????????ADO.NET???????????????????????????????????SealDBModel.edmx??UcmsDBModel.edmx??
????2??SealDBModel?????????????Server?ж???????????С?????????UcmsDBModel???????????????????????????
namespace Seal_Services
{
public class seal_testServer : BaseServer<seal_test>?? Iseal_usersServer
{
public void TTTT()
{
try
{
seal_test test = new seal_test()
{
name = "1111"??
age = 1
};
base.AddEntity(test);
base.db.SaveChanges();
BaseUCMSServer<au_Role> ucmsserver = new BaseUCMSServer<au_Role>();
au_Role role = new au_Role();
role = ucmsserver.FindEntitie(c => c.id == 7);
role.id=10;//????
role.role_name = "BBBBBBBBBBB";
ucmsserver.UpdateEntity(role);
ucmsserver.db.SaveChangesForUCMS();
}
catch (System.Exception ex)
{
throw ex;
}
}
}
}
????3????δ????????????????????????????????????????Ч?????????????????????????????????????????????EF?????????????????????????????????????????TransactionScope?ɡ?
????4?????????????????δ???
namespace Seal_Services
{
public class seal_testServer : BaseServer<seal_test>?? Iseal_usersServer
{
public void TTTT()
{
using (TransactionScope scope = new TransactionScope())
{
try
{
seal_test test = new seal_test()
{
name = "1111"??
age = 1
};
base.AddEntity(test);
base.db.SaveChanges();
BaseUCMSServer<au_Role> ucmsserver = new BaseUCMSServer<au_Role>();
au_Role role = new au_Role();
role = ucmsserver.FindEntitie(c => c.id == 7);
role.role_name = "BBBBBBBBBBB";
ucmsserver.UpdateEntity(role);
ucmsserver.db.SaveChangesForUCMS();
scope.Complete();
}
catch (System.Exception ex)
{
throw ex;
}
}
}
}
}
????5?????????????????????????Server????????“ ???????????? Open ????? ”?????????????????????????????????????????????????????????????????????????????????
????6??????????(?????????????????????...)?????????????SQL??????????????TransactionScope?????????
????7???? Sql Server Configuration Manager????????SQL Server??????????????????????????????????????????????????????????? ???????-ж?? ??? Express LocalDB?????????ж?????????????У?????С??????......???????????
????????
????1)??EF??????????????????????????????????[ ???????ADO.NET?????????? ]???·??????TransactionScope??????????????[ Express LocalDB ]??
????2)????EF????????????????У?????????[ SQL???? ]?????????????????????в??????????????????EF5.0??????EF6.0?С?
????????????Win8.1?? Sql Server 2008 R2?? Visual Studio 2013 Professional 2013 Update3