问题更新LINQ结果与匿名类型...只读? [英] Problem updating LINQ results with anonymous type...read only?

查看:115
本文介绍了问题更新LINQ结果与匿名类型...只读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在学习LINQ和所遇到的问题。我创建对罗斯文数据库的简单查询,而我塑造应该返回的字段。问题是运行后,我不能修改任何字段在我AspxGridView。

I'm learning LINQ and have run into a problem. I created a simple query against the northwind db, and I'm shaping the fields that should be returned. The problem is After run , I can't modify any of the fields in my AspxGridView .

<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" 
    AutoGenerateColumns="False" KeyFieldName="CategoryID">
    <Columns>
        <dxwgv:GridViewCommandColumn VisibleIndex="0">
            <EditButton Visible="True">
            </EditButton>
            <NewButton Visible="True">
            </NewButton>
            <DeleteButton Visible="True">
            </DeleteButton>
        </dxwgv:GridViewCommandColumn>
        <dxwgv:GridViewDataTextColumn Caption="CategoryID" FieldName="CategoryID" 
            VisibleIndex="1">
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Caption="CategoryName" FieldName="CategoryName" 
            VisibleIndex="2">
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Caption="Description" FieldName="Description" 
            VisibleIndex="3">
        </dxwgv:GridViewDataTextColumn>
    </Columns>
</dxwgv:ASPxGridView>

C#语法:

protected void Page_Load(object sender, EventArgs e)
{
    NorthwindDataContext db = new NorthwindDataContext();
    var r = db.Categories
        .Select(p=>new {p.CategoryID,p.CategoryName,p.Description});
    ASPxGridView1.DataSource = r;
    ASPxGridView1.DataBind();
}

你们可能会说这是对问题的 VAR 匿名类型。但我总是需要使用匿名type.How来解决这个问题。

You guys may say it's problem for var anonymous type .But i always need to use anonymous type.How to solve this problem

推荐答案

不认为这是可能的。

匿名类型是由一个或多个公共的只读属性的类类型。

Anonymous types are class types that consist of one or more public read-only properties.

通过 http://msdn.microsoft.com

这篇关于问题更新LINQ结果与匿名类型...只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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