BLToolKIT Entity Framework 需要帮助
BLToolKIT to Entity Framework help needed
我正在创建一种检查产品密钥的方法。在 bltoolkit 中一切正常,代码是
private void CheckKey()
{
try
{
using (DbManager db = new DbManager())
{
DataTable dt = db
.SetCommand("SELECT TOP 1 * FROM TblReg WHERE ProductKey=@ProductKey",
db.Parameter("@ProductKey", CommanClass.strRegkey))
.ExecuteDataTable();
if (dt.Rows.Count == 0)
{
GetSoftKey = false;
strSoftKey = null;
}
else
{
strSoftKey = dt.Rows[0].Field<string>("ProductKey");
GetSoftKey = true;
}
}
if ((GetSoftKey == true) && (strSoftKey != null))
{
if (strSoftKey == CommanClass.strRegkey)
{
SoftwareKey = true;
}
else
{
SoftwareKey = false;
}
}
}
catch (Exception)
{
SoftwareKey = false;
}
}
现在,当我尝试使用 entity framework 编写方法来检查产品密钥时,我对如何将 DataTable 变量 DataTable dt = login
传递到实体上下文并设置实体查询参数 [=14] 感到困惑=], 密码是
private void CheckKey()
{
try
{
using (loginEntities login = new loginEntities())
{
var pKey= from pk in login.tblSoftRegs
where pk.ProductKey == pk.ProductKey
select pk.ProductKey.FirstOrDefault();
if (pKey.Count() == 0)
{
GetSoftKey = false;
strSoftKey = null;
}
else
{
strSoftKey = ("ProductKey");
GetSoftKey = true;
}
}
if ((GetSoftKey == true) && (strSoftKey != null))
{
if (strSoftKey == CommanClass.busRegkey)
{
SoftwareKey = true;
}
else
{
SoftwareKey = false;
}
}
}
catch (Exception)
{
SoftwareKey = false;
}
}
等待社区贡献...
你快搞定了。如果找到 none,FirstOrDefault 将为 return null,并且您将局部变量直接绑定到 LINQ 查询中。像这样:
var pKey= from pk in login.tblSoftRegs
where pk.ProductKey == CommanClass.strRegkey
select pk.ProductKey.FirstOrDefault();
if (pKey == null)
{
GetSoftKey = false;
strSoftKey = null;
}
else
{
strSoftKey = ("ProductKey");
GetSoftKey = true;
}
我正在创建一种检查产品密钥的方法。在 bltoolkit 中一切正常,代码是
private void CheckKey()
{
try
{
using (DbManager db = new DbManager())
{
DataTable dt = db
.SetCommand("SELECT TOP 1 * FROM TblReg WHERE ProductKey=@ProductKey",
db.Parameter("@ProductKey", CommanClass.strRegkey))
.ExecuteDataTable();
if (dt.Rows.Count == 0)
{
GetSoftKey = false;
strSoftKey = null;
}
else
{
strSoftKey = dt.Rows[0].Field<string>("ProductKey");
GetSoftKey = true;
}
}
if ((GetSoftKey == true) && (strSoftKey != null))
{
if (strSoftKey == CommanClass.strRegkey)
{
SoftwareKey = true;
}
else
{
SoftwareKey = false;
}
}
}
catch (Exception)
{
SoftwareKey = false;
}
}
现在,当我尝试使用 entity framework 编写方法来检查产品密钥时,我对如何将 DataTable 变量 DataTable dt = login
传递到实体上下文并设置实体查询参数 [=14] 感到困惑=], 密码是
private void CheckKey()
{
try
{
using (loginEntities login = new loginEntities())
{
var pKey= from pk in login.tblSoftRegs
where pk.ProductKey == pk.ProductKey
select pk.ProductKey.FirstOrDefault();
if (pKey.Count() == 0)
{
GetSoftKey = false;
strSoftKey = null;
}
else
{
strSoftKey = ("ProductKey");
GetSoftKey = true;
}
}
if ((GetSoftKey == true) && (strSoftKey != null))
{
if (strSoftKey == CommanClass.busRegkey)
{
SoftwareKey = true;
}
else
{
SoftwareKey = false;
}
}
}
catch (Exception)
{
SoftwareKey = false;
}
}
等待社区贡献...
你快搞定了。如果找到 none,FirstOrDefault 将为 return null,并且您将局部变量直接绑定到 LINQ 查询中。像这样:
var pKey= from pk in login.tblSoftRegs
where pk.ProductKey == CommanClass.strRegkey
select pk.ProductKey.FirstOrDefault();
if (pKey == null)
{
GetSoftKey = false;
strSoftKey = null;
}
else
{
strSoftKey = ("ProductKey");
GetSoftKey = true;
}