如何在silverlight中从WCF域服务类方法将数据添加到另一个类?

发布于 2025-01-06 21:28:58 字数 1272 浏览 0 评论 0原文

您好,我正在 Silverlight 中使用 WCF RIA 服务类。

我确实有一个名为 mcChart 的折线图控件,其中我已将项目源绑定到 customer< 类的 DateAmount 属性/代码>。

public class Customer
    { 
      public DateTime Date{ get; set; }
      public int Amount{ get; set; }    
    } 

我确实有通过 WCF ria 域服务类访问 sql 表 gardenwater{Id, Date, Amt} 的方法:

public IQueryable<gardenwater> GetGardenwaters()
        {
            return this.ObjectContext.gardenwaters;
        }

现在我想将数据存储在 List; cust = new List(); 以便可以在图表中显示。

我已经尝试过这样的:

EntityQuery<gardenwater> inquery = from c in wdc.GetGardenwatersQuery()
                                   select new { Date =Convert.ToDateTime(c.Date), Amount =Convert.ToInt32(c.usedwater) };

然后

foreach (var gardenWater in inquery )
            {
                cust.Add(new Customer() { Date = Convert.ToDateTime(gardenWater.Date), Amount = Convert.ToInt32(gardenWater.usedwater) });
            }

 mcChart.DataContext = cust;

执行上述所有操作我无法得到任何好的结果。

我想通过在类属性中存储SQL表数据来显示数据。

请建议我可以做什么或我犯了什么错误?

Hi i am using WCF RIA services class in Silverlight.

I do have a line chart control named mcChart in which i have bound the item source to Date and Amount properties of class customer.

public class Customer
    { 
      public DateTime Date{ get; set; }
      public int Amount{ get; set; }    
    } 

I do have this method through WCF ria domain service class to access the sql table gardenwater{Id, Date, Amt}:

public IQueryable<gardenwater> GetGardenwaters()
        {
            return this.ObjectContext.gardenwaters;
        }

Now i want to store the data in List<Customer> cust = new List<Customer>(); so that it can be shown in the chart.

I have tried like this :

EntityQuery<gardenwater> inquery = from c in wdc.GetGardenwatersQuery()
                                   select new { Date =Convert.ToDateTime(c.Date), Amount =Convert.ToInt32(c.usedwater) };

and then

foreach (var gardenWater in inquery )
            {
                cust.Add(new Customer() { Date = Convert.ToDateTime(gardenWater.Date), Amount = Convert.ToInt32(gardenWater.usedwater) });
            }

 mcChart.DataContext = cust;

Doing all the above i am not able to get any good results.

I want to display the data through storing SQL table data in Class properties.

Please suggest me what can i do or what mistakes i am doing ?

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

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

发布评论

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

评论(1

滥情空心 2025-01-13 21:28:58

我现在已经解决了...我可以使用以下

            private ContextName context;
            private LoadOperation LoadGardenWater;
            private void GetGardenWater()
            {
                context = new ContextName();
                context.GardenWaters.Clear();
                var query = context.GetGardenWaterQuery();
                LoadGardenWater = context.Load<GardenWater>(query);
                LoadGardenWater.Completed +=new EventHandler(LoadGardenWater_Completed);
            }

            void LoadGardenWater_Completed(object sender, EventArgs e)
            {
                List<Customer> cust = new List<Customer>();
                if (LoadGardenWater.Entities != null || LoadGardenWater.Entities.Count()> 0)
                {
                    foreach (GardenWater item in LoadGardenWater.Entities)
                    {
                        cust.Add(new Customer()
                        {
                            Amount = Convert.ToInt32(item.Amount),
                            Date = Convert.ToDateTime(item.Date)
                        });
} 
}
}

I got it resolved by now...i can use following

            private ContextName context;
            private LoadOperation LoadGardenWater;
            private void GetGardenWater()
            {
                context = new ContextName();
                context.GardenWaters.Clear();
                var query = context.GetGardenWaterQuery();
                LoadGardenWater = context.Load<GardenWater>(query);
                LoadGardenWater.Completed +=new EventHandler(LoadGardenWater_Completed);
            }

            void LoadGardenWater_Completed(object sender, EventArgs e)
            {
                List<Customer> cust = new List<Customer>();
                if (LoadGardenWater.Entities != null || LoadGardenWater.Entities.Count()> 0)
                {
                    foreach (GardenWater item in LoadGardenWater.Entities)
                    {
                        cust.Add(new Customer()
                        {
                            Amount = Convert.ToInt32(item.Amount),
                            Date = Convert.ToDateTime(item.Date)
                        });
} 
}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文