嗨,我如何修复此错误:属性或索引器'状态'无法分配 - 它是只读的 [英] Hi, How Do I Fix This Error : Property Or Indexer 'Status' Cannot Be Assigned To -- It Is Read Only
本文介绍了嗨,我如何修复此错误:属性或索引器'状态'无法分配 - 它是只读的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
this is my code
var filteredQuery = ProjectProvider.GetProjects()
.Select(a => new ProjectGrid()
{
Id = a.Id,
ClientId = a.ClientId,
ProjectName = a.ProjectName,
this is where my error is -> StatusType = a.Status,
CostCode = a.CostCode,
Description = a.Description
});
推荐答案
在ProjectGrid中确保StatusType有一个get和(非私有)设置。
In ProjectGrid make sure StatusType has a get and (non-private) set.
public YourType StatusType {get; set;}
在类定义中它只有一个得到。或者可能是类型在别处计算并且不是标准属性。如果是这种情况,你需要设置类,使其StatusType返回你想要的状态。
In its class definition it'll only have a "get". Or it could be that the type is computed elsewhere and isn't a standard property. If that's the case you'll need to set the class up such that its StatusType returns the status you want.
public YourType StatusType
{
get
{
// look at how the status type is calculated and work out
// from that how to set it
return SomeFunctionThatCalculatesType();
}
}
鉴于您发布的信息很少,任何后续问题都不太可能回答,我们不知道你的系统,它的规则,我们无法访问你的代码和数据库。
Given the minimal information you have posted, it is unlikely any follow-up questions can be answered, we don't know your system, its rules, we can't access your code and databases.
使用public< datatype>声明属性。 status {get; set;}
或类似
public< datatype>状态;
这可能会解决您的问题
Declare the property with public <datatype> status{get;set;}
or like
public <datatype> status;
this will probably solve your problem
这篇关于嗨,我如何修复此错误:属性或索引器'状态'无法分配 - 它是只读的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文