2016-08-20 58 views
0

我遇到了實體問題和保存問題我想更新記錄的值,因此我正在執行以下操作。用戶沒有物理輸入時引起問題的小數

我在其他oens中使用以下,但它不在這裏工作某些原因來保存記錄它說,密鑰已經存在。

_dal.portalEntities.Entry(_custInfo).State = System.Data.Entity.EntityState.Modified; 
_dal.portalEntities.SaveChanges(); 
_dal.portalEntities.Entry(_custInfo).Reload(); 

這裏是我的主程序

tblPortalUser _users; 
_users = _dal.GetUserRecordByEmail(_myuser.EmailAddress.ToLower()); 
//password is the same warn the user as current 
if (PasswordHash.ValidatePassword(password.Text, _users.password) == true) 
{  
    lblerror.Text = "Password choose a password you have not used before"; 
    }else 
lblerror.Text = "Current Password is invalid."; 
      // if password is the same as the confirm password then proceed if not warn the user 
if (password.Text == confirmpass.Text) 
{ 
    _users.password = PasswordHash.HashPassword(password.Text); 
    _dal.portalEntities.SaveChanges(); 
//lets send out the verification codes for the email and sms 
    _notifications.sendNotification(new Guid(portalbl.BLConstants.resetPasswordEmail), _custInfo.firstName + " " + _custInfo.lastName, "", _custInfo.email.ToLower(), "", "", portalbl.BLConstants.portalNotifications.Email, ""); 
Response.Redirect(@"~\myaccount\logout.aspx", false); 
} 

GetUserRecordByEmail

public tblPortalUser GetUserRecordByEmail(string Email) 
    { 
     try 
     { 
      tblPortalUser _user; 

      _user = (from _users in _dal.portalEntities.tblPortalUsers 
        where _users.EmailAddress.ToLower() == Email 
        select _users).FirstOrDefault(); 


      return _user; 
     } 
     catch (Exception ex) 

     { 
      string inner = string.Empty; 
      if (ex.InnerException != null) 
      { 
       inner = ex.InnerException.ToString(); 
      } 
      return null; 
     } 
    } 

編輯1 唯一的例外是在這裏展示對不起,我不就沒怎麼包括圖像沒有鏈接當分數低於10時

https://snag.gy/QMSzaE.jpg

+0

可以請你展示異常,所以我們可以知道什麼是問題,拋出異常在哪裏? –

+0

@TarekAboELkheir我已經在我的編輯中包含了一個屏幕截圖我只是想編輯一個現有的記錄,所以我不知道是什麼問題是非常誠實的 – rogue39nin

回答

0

從屏幕截圖,異常清晰,你需要先拆下用戶並重新連接它,它會工作

看看這篇文章:Attaching and Detaching Objects

+0

@Tarerk你可以提供一個例子請在這 – rogue39nin

+0

@Tarerik可以您請示例不只是一個鏈接 – rogue39nin