如何将 WCF RIA 服务查询实体绑定到 WPF 标签?

发布于 2024-12-10 13:33:30 字数 1438 浏览 0 评论 0原文

我真的很想知道为什么在第一种情况下我可以将数据绑定到 DataGrid 而在第二种情况下它根本不起作用。谢谢你的任何线索!

下面是代码:

        Guid id = Guid.Parse("BCBBF129-30ED-400B-9D63-403ED79FDFC7");
        EntityQuery<Alert> alert = this._preDomainContext.GetAlertQuery(id);  
        LoadOperation<Alert> l = this._preDomainContext.Load(alert);
        dataGrid1.ItemsSource = l.Entities; // <- It works fine

        label1.Content = l.Entities.ElementAt(0).Message; // It gives an error

XAML:

<sdk:DataGrid   AutoGenerateColumns="True" Height="100" 
HorizontalAlignment="Left" Margin="173,154,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="120" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="194,114,0,0" Name="label1" VerticalAlignment="Top" Width="120" />

错误是:

索引超出范围。必须为非负数且小于集合的大小。 参数名称:index

哦!在这两种情况下,当我调试时,我看不到 l.Entities 的任何值以及 l.Entities.ElementAt(0).Message。但是当页面出现在 DataGrid 下时,我可以看到数据,但同时我收到上面的错误...

我不确定...但是是否可以在页面出现之前看到数据?根本看不到任何数据真的很不舒服......

更新:

    [RequiresAuthentication]
    [EnableClientAccess()]
    public class PreDomainService : LinqToEntitiesDomainService<PreEntities>
    {


    public  Alert GetAlert(Guid id)
        {
            return this.ObjectContext.Alerts.Where(a=>a.ID == id).FirstOrDefault();
        }

I really want to know why in the first case I can bind data to the DataGrid and in the second case it doesn't work at all. Thank you for any clue!!!

Here is the code:

        Guid id = Guid.Parse("BCBBF129-30ED-400B-9D63-403ED79FDFC7");
        EntityQuery<Alert> alert = this._preDomainContext.GetAlertQuery(id);  
        LoadOperation<Alert> l = this._preDomainContext.Load(alert);
        dataGrid1.ItemsSource = l.Entities; // <- It works fine

        label1.Content = l.Entities.ElementAt(0).Message; // It gives an error

And the XAML:

<sdk:DataGrid   AutoGenerateColumns="True" Height="100" 
HorizontalAlignment="Left" Margin="173,154,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="120" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="194,114,0,0" Name="label1" VerticalAlignment="Top" Width="120" />

And error is:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Oh! On both cases when I debug I cannot see any values for the l.Entities and as well as
l.Entities.ElementAt(0).Message. But when page appears under the DataGrid I can see the data but at the same time I get the error above...

I am not sure... But is it possible to see the data before when a page appears? It's really uncomfortable don't see any data at all...

UPDATES:

    [RequiresAuthentication]
    [EnableClientAccess()]
    public class PreDomainService : LinqToEntitiesDomainService<PreEntities>
    {


    public  Alert GetAlert(Guid id)
        {
            return this.ObjectContext.Alerts.Where(a=>a.ID == id).FirstOrDefault();
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2024-12-17 13:33:30

我假设您的实体集合是空的。

I would assume that your Entities collection is empty.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文