我在服务器上有一个项目的svn repo,我曾经从中检出机器上的项目并且可以正常工作。
我的项目使用MVC 3和Entity Framework。当我结帐项目时,我必须删除模型并重新生成模型(例如.edmx文件)并更新web.config文件。
此过程非常耗时,我不喜欢有任何解决方法吗??
这是我的连接字符串
<connectionStrings>
<add name="AppConfigDBEntities" connectionString="metadata=res://*/Models.AppConfigModel.csdl|res://*/Models.AppConfigModel.ssdl|res://*/Models.AppConfigModel.msl;provider=System.Data.SqlClient;provider connection string="data source=INMHVIHWD025\SQLEXPRESS;initial catalog=test_db_name;persist security info=True;user id=admin;password=admin;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
...
...
...
</connectionStrings>
如果我不重新生成模型,则会遇到错误
2018-11-06 16:27:47,080 [5] INFO MyApp.Controllers.homeController [(null)] - User Logout Successfully...!
2018-11-06 16:27:47,131 [6] INFO MyApp.Controllers.homeController [(null)] - Inside homecontroller Index ()
2018-11-06 16:27:53,015 [5] INFO MyApp.Controllers.homeController [(null)] - Inside homecontroller Index ()
2018-11-06 16:28:08,722 [5] INFO MyApp.Controllers.homeController [(null)] - Inside homecontroller Login Post ()
2018-11-06 16:28:23,733 [5] ERROR MyApp.Controllers.homeController [(null)] - Exception inside Login () : at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
at System.Data.EntityClient.EntityConnection.Open()
at System.Data.Objects.ObjectContext.EnsureConnection()
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at System.Data.Objects.ELinq.ObjectQueryProvider.<>c__11`1.<GetElementFunction>b__11_1(IEnumerable`1 sequence)
at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
at MyApp.Controllers.homeController.Login(FormCollection form) in C:\Visual Studio 2017 Workspace\Project1\MyApp\Controllers\homeController.cs:line 116
2018-11-06 16:28:23,738 [6] INFO MyApp.Controllers.homeController [(null)] - Inside homecontroller Index ()
下面是我的控制器代码。
[HttpPost]
public ActionResult Login(FormCollection form)
{
log.Info("Inside homecontroller Login Post () ");
string uname = form["uname"];
string password = form["password"];
if (string.IsNullOrEmpty(uname) || string.IsNullOrEmpty(password)) {
TempData["errorMsg"] = "Username or password required..!";
log.Info("Username or password required..!");
return RedirectToAction("Index", "Home");
}
try
{
string encryptedPwd = MyApp.Utils.PasswordUtils.Encrypt(password);
var myUser = userProfileDBObj.tbl_user_profile.FirstOrDefault(u => u.uname == uname && u.password == encryptedPwd);
if (myUser != null)
{
List<long> roles = (List<long>)usersRoleDBObj.tbl_users_roles.Where(r => r.user_id == myUser.id).Select(r => r.role_id).ToList();
List<string> roles_funtionalities = new List<string>();
foreach (var roleId in roles)
{
List<string> roles_func = rolesFunDBObj.tbl_roles_functionality.Where(x => x.role_id == roleId).Select(x => x.functionality_id).ToList();
foreach (string item in roles_func)
{
Debug.WriteLine(item.ToString());
if (!roles_funtionalities.Contains(item))
roles_funtionalities.Add(item.ToString());
}
}
log.Info("roles_funtionalities.Count :" + roles_funtionalities.Count);
foreach (string item in roles_funtionalities)
{
log.Info(item.ToString());
}
TempData["userFunctionalities"] = roles_funtionalities;
TempData["uname"] = myUser.uname;
TempData["uId"] = myUser.id;
log.Info("User LoggedIn Successfully..!");
return RedirectToAction("userHome", "Home");
}
else
{
TempData["errorMsg"] = "Username or password incorrect..!";
log.Info("Username or password incorrect..!");
return RedirectToAction("Index", "Home");
}
}
catch (Exception e)
{
log.Error("Exception inside Login () :" + e.StackTrace);
}
return RedirectToAction("Index", "Home");
}