Linq获取错误:属性或索引器'AnonymousType#1.Password'无法分配 - 它是只读的 [英] Linq Getting error : Property or indexer 'AnonymousType#1.Password' cannot be assigned to -- it is read only

查看:162
本文介绍了Linq获取错误:属性或索引器'AnonymousType#1.Password'无法分配 - 它是只读的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了这些代码以便在首次登录时更改我的密码,但是此代码收到错误,这里是我的代码



i have write these code for change my password on first login but this code is getting error here is my code

using (extractDataContext context = new extractDataContext())
{
var Query = (from t in context.userDetails where txtUserID.Text == t.UserID && SimpleHash.Encrypt_QueryString(txtPassword.Text ) == t.Password select new { t.Password }).Single();

if (Query!=null)
{
Query .Password = SimpleHash.Encrypt_QueryString(txtPassword.Text);  --> Error Shows in bolted text
context.SubmitChanges();
}

}

推荐答案

请将Single更改为FirstOrDefault或First.Single返回标量因此,你不能像财产一样使用它

Please Change Single to FirstOrDefault or First.Single returns a scalar value.So you can't use it like property
var Query = (from t in context.userDetails where txtUserID.Text == t.UserID && SimpleHash.Encrypt_QueryString(txtPassword.Text ) == t.Password select new { t.Password }).FirstOrDefault();



希望这有助于


Hope this helps


这篇关于Linq获取错误:属性或索引器'AnonymousType#1.Password'无法分配 - 它是只读的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆