为什么Breeze jquery Where / Take / Order在没有nodb的BreezeJs中不起作用,

时间:2013-06-07 15:26:01

标签: breeze

这是我的代码: 服务器Web API

=======================================


    public class OwnerDto {
            public int OwnerId { set; get; }
            public string OwnerName { set; get; }
        }
     [HttpGet]
            public IEnumerable GetOwner()
            {

                IEnumerable result = new[] { 
                    new OwnerDto { OwnerId = 1, OwnerName = "Test1" },
                    new OwnerDto { OwnerId = 2, OwnerName = "Test2" },
                    new OwnerDto { OwnerId = 3, OwnerName = "Test3" },
                    new OwnerDto { OwnerId = 4, OwnerName = "Test4" }
                };

                return result;
            }

js code



    var dataService = new breeze.DataService({
                serviceName: "/api/owner/",
                hasServerMetadata: false,
            });

            var manager = new breeze.EntityManager({ dataService: dataService });

            var store = manager.metadataStore;

            //metadataStore.namingConvention = namingConv;
            store.addEntityType({
                shortName: "Owner",
                namespace: "Test.Owner",
                dataProperties: {
                    OwnerId: { dataType: breeze.DataType.Int32, isPartOfKey: true },
                    OwnerName: { dataType: breeze.DataType.String}
                }
            });


            var op = breeze.FilterQueryOp;
            var query = new breeze.EntityQuery()
                .from("GetOwner")
                .where("ownerId",op.Equals,2);

            manager.executeQuery(query).then(function (data) {
                ko.applyBindings(data, $("#SearchResult")[0]);
            }).fail(function (e) {
                alert(e);
            });

Html代码


    p- data-bind="visible: !results" Fetching data ..
    ul- data-bind="foreach: results, visible: results" style="display:none" 

    span- data-bind="text: OwnerName"
    span- data-bind="text: OwnerId"

========================================== 问题是所有数据都可以显示,但过滤器(where / take / order ...)不起作用。 任何想法,非常感谢!

1 个答案:

答案 0 :(得分:0)

我相信原因是您的查询方法会返回IEnumerable。这些谓词(where / take / order)仅适用于返回IQueryable<T>的服务端点。试试这个:

[HttpGet]
public IQueryable GetOwner()
            {

                IEnumerable result = new[] { 
                    new OwnerDto { OwnerId = 1, OwnerName = "Test1" },
                    new OwnerDto { OwnerId = 2, OwnerName = "Test2" },
                    new OwnerDto { OwnerId = 3, OwnerName = "Test3" },
                    new OwnerDto { OwnerId = 4, OwnerName = "Test4" }
                };

                return result.AsQueryable();
            }