Errors when using Breeze with EF

我的梦境 提交于 2019-12-24 10:57:18

问题


I am using breezejs with EF. My Web API is returning an "object" consisting of properties from a number of linked entities which I use to bind to a grid. I will need to update some of the properties later and I want to cache the data , hence breeze. I am using the noDB sample to create a custom Entity.

The first problem is that breeze seems to expect a property called name to be passed in the addEntityType method or it throws an error The 'structuralTypeName' parameter must be a 'string'.

The second problem is the call to structuralType._fixup in breeze on line 4742 seems to be throwing the following error Object # has no method '_fixup' though I can see the function exists.

Can anyone point out what I am doing wrong in the code below ? The error is in the addEntityType call.

manager.metadataStore.addEntityType({
            name: "Transcription", shortName: "Transcription", namespace: "Etrans.Data.Models", autoGeneratedKeyType: breeze.AutoGeneratedKeyType.Identity,
            dataProperties: {
                audio: { dataType: DataType.String }, clientID: { dataType: DataType.Int32 }, clientName: { dataType: DataType.String },
                clinicianfirstname: { dataType: DataType.String }, clinicianlastname: { dataType: DataType.String }, Notes: { dataType: DataType.String },
                status: { dataType: DataType.String }, transcriptionid: { dataType: DataType.Int32, isPartOfKey: true }, user: { dataType: DataType.String }
            }

        });
        manager.metadataStore.registerEntityTypeCtor("Transcription", null, customReportFields);

On the server side I have the data layer in a project called Etrans.Data. The web API invokes a repository which queries the data layer. In this instance it is querying an Entity called Transcription (Etrans.Data.Models.Transcription) and a number of linked entities.


回答1:


@shai - I regret the confusion you encountered which appears to be a consequence of the evolution of the BreezeJS client metadata definition API. But I do not fully understand your recommendation.

The HotTowel template and HT NuGet package(s) do depend upon an older version of the BreezeJS NuGet package which may have had an addEntityType method that has since changed (I haven't looked). I'll work with John Papa to get the HT stuff updated.

But I don't understand what you're telling people to do. The HT templates work as delivered if you stay within the boundaries of their then-official-capabilities. FWIW, client-side metadata definition was in beta at the time and we said that its API was likely to change. It is still a work in progress.

Updating an app to the latest versions of dependent packages will change some things of course. That is why one would upgrade.

Are you saying that there is a continuing problem after you update to the latest Breeze NuGet packages? Are you pointing to some discrepancy between the latest Breeze NuGet packages (1.3.3 as I write) and the latest source in GitHub. There is always some discrepancy there - BreezeJS on GitHub always holds our latest ideas ... many of which will change and none of them approved for development use. I would advise people to stick with official releases.

Are you telling folks they shouldn't use HotTowel? Why? The problem you encountered is not in a mainstream feature (it's not even an official feature of HT).

OTOH, I both understand and fully agree with the recommendation to upgrade all HT dependent packages (including Durandal and Toastr as well as Breeze) to latest versions.

Thanks for hanging in there with us.




回答2:


On my machine, Breeze throws an error with this message on your call to addEntityType:

Error configuring an instance of 'EntityType'. Unknown property: 'name'.

Basically "name" is not a valid configuration parameter to the addEntityType call. So eliminating your 'name' property, which isn't needed because breeze builds it up out of the shortName and the namespace, your code becomes:

manager.metadataStore.addEntityType({
        shortName: "Transcription",
        namespace: "Etrans.Data.Models",
        autoGeneratedKeyType: breeze.AutoGeneratedKeyType.Identity,
        dataProperties: {
            audio: { dataType: DataType.String },
            clientID: { dataType: DataType.Int32 },
            clientName: { dataType: DataType.String },
            clinicianfirstname: { dataType: DataType.String },
            clinicianlastname: { dataType: DataType.String },
            Notes: { dataType: DataType.String },
            status: { dataType: DataType.String },
            transcriptionid: { dataType: DataType.Int32, isPartOfKey: true },
            user: { dataType: DataType.String }
        }
    });

which runs just fine.

Hope this helps.




回答3:


TO ALL THOSE USING THE HOT TOWEL TEMPLATE... SUGGEST GRABBING THE LATEST BREEZE CODE DIRECTLY AND NOT USE THE NUGET UPDATE ...AS ON 15/05/2013

Damn..I just wasted a day on this. The nuget package source and the package available from breezejs.com seem to be very different.I downloaded the latest source from breezejs and the lines I mentioned in my earlier comment don't exist as a matter of fact the whole addEntityType function is different... there is no structuralType.name!! I did use nuget to update to the latest stable source. Not sure whether this is from the hot towel template or from nuget.



来源:https://stackoverflow.com/questions/16533508/errors-when-using-breeze-with-ef

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!