“重复”使用 NHibernate、Linq to NHibernate 和 Castle.Windsor 时将数据填充到 Silverlight 4 Gridview 中

发布于 2024-10-08 22:36:38 字数 2499 浏览 0 评论 0原文

我当前遇到的问题如下:

我的 Silverlight 4 应用程序中有一个 Gridview,并且它填充了数据。但是,数据是从数据库带回的对象集合中的第一个条目,并在网格视图中重复 x 次。

当我在 DAL 和域服务上设置断点时,带回的数据是正确的,即它带回集合中的所有不同对象。

如果我将数据绑定到非 Silverlight 组件,则不会出现这个问题。

现在,对于一些代码,以下是我在 Silverlight 应用程序中绑定数据的方式:

 private void BindData()
    {
        _ctx = new ManufacturingDomainContext();

         _loadOp = _ctx.Load( _ctx.GetWorkCellLoadGraphDataByIdQuery( "Test", DateTime.Today, DateTime.Today.AddDays( 14 ) ), TestCallBack, null );
    }

    private void TestCallBack(LoadOperation<WorkCellLoadGraphData> obj)
    {
        CustomerGrid.ItemsSource = _loadOp.Entities;
    }

域服务代码是:

 public IEnumerable<WorkCellLoadGraphData> GetWorkCellLoadGraphDataById(string workCellId, DateTime startDate, DateTime endDate)
    {
        WorkCellLoadGraphData data = new WorkCellLoadGraphData();

        var result = ManufacturingDao.Instance.GetWorkCellLoadGraphDataByIdA(workCellId, startDate, endDate);


        return result;
    }

最后 DAL 代码是:

public IList GetWorkCellLoadGraphDataByIdA(string workCellId, DateTime startDate, DateTime endDate) { IList 结果 = new List();

        using (var session = this.GetSession())
        {

            var criteria = session.CreateCriteria(typeof(WorkCellLoadGraphData));

            criteria.SetProjection(
                Projections.ProjectionList()
                    .Add(Projections.Property(WorkCellLoadGraphData.WorkCellIdPropertyName), "WorkCellId")

                    .Add(Projections.Property(WorkCellLoadGraphData.FromTimePropertyName), "FromTime")
                    .Add(Projections.Property(WorkCellLoadGraphData.DurationPropertyName), "DurationInMinutes")

                );

            criteria.Add(Restrictions.InsensitiveLike(WorkCellLoadGraphData.WorkCellIdPropertyName, workCellId));
            criteria.Add(Restrictions.Between(WorkCellLoadGraphData.FromTimePropertyName, startDate, endDate));

            criteria.SetResultTransformer(new AliasToBeanResultTransformer(typeof(WorkCellLoadGraphData)));

            results = criteria.List<WorkCellLoadGraphData>();
        }

        foreach (var x in results)
            Logger.Info(x.ToString());

        return results;
    }

作为主题行中提到的所有技术的初学者,我不确定哪个领域可能存在问题。我尝试过设置断点,但是对于异步调用,事情并不那么容易理解。

另外,我必须补充一点,通常情况下,我会从 POCO 类调用 DAL 代码,而不是完全绕过 POCO。

有人可以帮忙吗?

大卫

The problem I'm currently having is as follows:

I have a Gridview in my Silverlight 4 application and it gets populated with data. However, the data is the first entry in an object collection that is brought back from the database and repeated x times in the grid view.

When I put a breakpoint on the DAL and the domain service, the data being brought back is correct i.e. it brings back all the distinct objects in the collection.

This is not a problem that manifests itself if I'm binding the data to a non Silverlight component.

Now for some code, here is how I'm binding the data in the Silverlight application:

 private void BindData()
    {
        _ctx = new ManufacturingDomainContext();

         _loadOp = _ctx.Load( _ctx.GetWorkCellLoadGraphDataByIdQuery( "Test", DateTime.Today, DateTime.Today.AddDays( 14 ) ), TestCallBack, null );
    }

    private void TestCallBack(LoadOperation<WorkCellLoadGraphData> obj)
    {
        CustomerGrid.ItemsSource = _loadOp.Entities;
    }

The domain service code is:

 public IEnumerable<WorkCellLoadGraphData> GetWorkCellLoadGraphDataById(string workCellId, DateTime startDate, DateTime endDate)
    {
        WorkCellLoadGraphData data = new WorkCellLoadGraphData();

        var result = ManufacturingDao.Instance.GetWorkCellLoadGraphDataByIdA(workCellId, startDate, endDate);


        return result;
    }

And finally the DAL code is:

public IList GetWorkCellLoadGraphDataByIdA(string workCellId, DateTime startDate, DateTime endDate)
{
IList results = new List();

        using (var session = this.GetSession())
        {

            var criteria = session.CreateCriteria(typeof(WorkCellLoadGraphData));

            criteria.SetProjection(
                Projections.ProjectionList()
                    .Add(Projections.Property(WorkCellLoadGraphData.WorkCellIdPropertyName), "WorkCellId")

                    .Add(Projections.Property(WorkCellLoadGraphData.FromTimePropertyName), "FromTime")
                    .Add(Projections.Property(WorkCellLoadGraphData.DurationPropertyName), "DurationInMinutes")

                );

            criteria.Add(Restrictions.InsensitiveLike(WorkCellLoadGraphData.WorkCellIdPropertyName, workCellId));
            criteria.Add(Restrictions.Between(WorkCellLoadGraphData.FromTimePropertyName, startDate, endDate));

            criteria.SetResultTransformer(new AliasToBeanResultTransformer(typeof(WorkCellLoadGraphData)));

            results = criteria.List<WorkCellLoadGraphData>();
        }

        foreach (var x in results)
            Logger.Info(x.ToString());

        return results;
    }

As a beginner at all the technologies mentioned in the subject line, I'm not sure which area could be the problem. I've tried putting in breakpoints but with the async calls, things are not so easy to follow.

Also, I must add that normally, I'd be calling the DAL code from my POCO classes, rather than bypassing the POCO completely.

Can anyone help?

David

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

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

发布评论

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

评论(1

甜中书 2024-10-15 22:36:38

好吧,在解决这个问题一段时间后,我们发现了问题所在。实际上,我们返回的对象集合看起来像这样:

  • “someID”、Today、1
  • “someID”、Tomorrow、1
  • “someID”、NextMonth、1

等等。

问题在于“someID”,因为我相信 Silverlight 期待一些独特的东西。因此,如果我们将数据传递为

  • “someID”,Today,1
  • “someID1”,Tomorrow,1
  • “someID2”,NextMonth,1,

则将返回“正确”数据。

我真的希望这对某人有帮助,因为我们在这方面浪费了很多时间。

Ok after struggling with this issue a while we found out what the problem was. Effectively, in our collection of objects being returned looked something like this:

  • "someID", Today, 1
  • "someID", Tomorrow, 1
  • "someID", NextMonth, 1

and so on.

The problem was with "someID" as I believe that Silverlight is expecting something unique. So if instead we passed the data out as

  • "someID", Today, 1
  • "someID1", Tomorrow, 1
  • "someID2", NextMonth, 1

the "correct" data would be returned.

I really hope this helps someone as we've wasted a lot of time on this.

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