Home > Net >  Update about EntityFramework writing problems
Update about EntityFramework writing problems

Time:03-09

Has the following methods: DAL layer
 
///& lt; summary>
///for the lock or unlock the account
///& lt;/summary>
///& lt; Param name="Locked" & gt; Locked & lt;/param>
///& lt; Param name="logno & gt;" Login account & lt;/param>
///& lt; Param name="loginName & gt;" Lock & lt;/param>
///& lt; Returns>
Public static bool ExecUserLocked (bool Locked, string logno, string loginName=null)
{
Try
{
Int result=0;
Using (CusProContext db=new CusProContext ())
{
If (Locked)
{
If (db) SysUser) Any ())
{
SysUser userobj=db. SysUser. First (a=& gt; A. ogno==logno);
Userobj. Locked=Locked;
Userobj. The Lockman=loginName;
Userobj. Lockdate=DateTime. Now;
}
}
The else
{
If (db) SysUser) Any ())
{
SysUser userobj=db. SysUser. First (a=& gt; A. ogno==logno);
Userobj. Locked=Locked;
Userobj. The Lockman="";
Userobj. Lockdate=null;
}
}

Result=the SaveChanges ();
}
Return result!=0? True, false;
}
The catch (Exception ex)
{
Throw the ex.
}
}


Business application layer call logic goes like this:
 
Public static string _logno _userna;//GridControl two values of the selected lines
///& lt; summary>
///locking out
///& lt;/summary>
///& lt; Param name="sender" & gt;
///& lt; Param name="e" & gt;
Private void BarToggleSwitch_ItemClick (object sender, DevExpress XtraBars. ItemClickEventArgs e)
{
If (_logno==string. The Empty | | _userna==string. The Empty)
{
MessageDxUtil. ShowTips (" did not choose to lock the account, please choose again!" );
return;
}

//account lockout
If (BarToggleSwitch. Checked)
{
If (MessageDxUtil. ShowYesNoAndTips (" sure you want to lock [" + _userna + "] account?" )==DialogResult. OK)
{
ContextHelper. ExecUserLocked (true, _logno, Portal. Gc. The UserInfo. Logno);
MessageDxUtil. ShowTips (" account lock success!" );
}

}
The else
{
ContextHelper. ExecUserLocked (false, _logno, null);
MessageDxUtil. ShowTips (" account unlock success!" );
}

//overloading data
InitData ();
}


The question now is, if condition update written, is invalid, and the else write method is normal, by the result of the SQL Server Profiler to track,

I have been tracking SysUser entity, of which the bool is Locked? Type value, and the database is the byte type, only 0 (false), 1 (true), the feeling is the problem here, don't know whether I, also please great god guide,

CodePudding user response:

Found the problem reasons, not written method has a problem,
But DevExpress add this patch:
 
//interface localization
//Thread. CurrentThread. CurrentUICulture=new System. Globalization, CultureInfo (" useful - Hans ");

As a direct result of:
 
If (MessageDxUtil. ShowYesNoCancelAndTips (" sure you want to lock [" + _userna + "] account?" )==DialogResult. Yes)

Incredibly don't enter the if, I go, who is a great god know this problem,

CodePudding user response:

The optimization, figure a too wordy,

Use FirstOrDefault (); Methods to check and then judge is not empty, use the First query is not enough to throw exceptions,
  •  Tags:  
  • C#
  • Related