Exception while parsing metadata in BreezeJS clien

2019-07-18 07:50发布

问题:

Prequel and version info:

BreezeJS client version: 1.5.2

Metadata generated on custom server via design-time EntityFramework model (6.1.2)

BreezeLabs EdmBuilder (1.0.5)

Had problems generating metadata also which can be read here: How to generate valid metadata from EF DBContext via EdmBuilder for OData v3/BreezeJS


Question/Problem:

Now the breeze client is throwing an error while interpreting the metadata.

Unable to process returned metadata: A nonnullable DataProperty cannot have a null defaultValue. Name: MySuperDuperEnum

The exception occurs in breeze.debug.js at line 7110 - function parseCsdlSimpleProperty(parentType, csdlProperty, keyNamesOnServer).

Whats going wrong here? Do I have wrong metadata?

Here is the metadata:

<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
    <edmx:DataServices m:DataServiceVersion="3.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
        <Schema Namespace="ODataMetaDataGenerator" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">

            <EntityType Name="MyObject" p5:ClrType="GreatPersistencyNamespace.Model.GreatStuff.MyObject, BreezeEval, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:p5="http://schemas.microsoft.com/ado/2013/11/edm/customannotation">
                <Key>
                    <PropertyRef Name="ID"/>
                </Key>
                <Property Name="ID" Nullable="false" Type="Edm.Int32" p7:StoreGeneratedPattern="Identity" xmlns:p7="http://schemas.microsoft.com/ado/2009/02/edm/annotation"/>
                <Property FixedLength="false" MaxLength="Max" Name="Name" Type="Edm.String" Unicode="true"/>
                <Property Name="IsActive" Nullable="false" Type="Edm.Boolean"/>
                <Property Name="IsGreat" Nullable="false" Type="Edm.Boolean"/>
                <Property FixedLength="false" MaxLength="Max" Name="Description" Type="Edm.String" Unicode="true"/>
                <Property Name="Address" Nullable="false" Type="ODataMetaDataGenerator.Address"/>
                <Property Name="BehaviourType" Nullable="false" Type="ODataMetaDataGenerator.BehaviourType"/>
            </EntityType>

            <EnumType Name="BehaviourType" UnderlyingType="Edm.Byte" p5:ClrType="GreatPersistencyNamespace.Model.GreatStuff.BehaviourType, BreezeEval, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:p5="http://schemas.microsoft.com/ado/2013/11/edm/customannotation">
                    <Member Name="RUDE" Value="1"/>
                    <Member Name="KIND" Value="2"/>
                    <Member Name="UNKNOWN" Value="3"/>
            </EnumType>

            <EntityContainer Name="TheGreatModelContainer" p5:UseClrTypes="true" xmlns:p5="http://schemas.microsoft.com/ado/2013/11/edm/customannotation"   >
                    <EntitySet EntityType="ODataMetaDataGenerator.MyObject" Name="MyObjects"/>
            </EntityContainer>

        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

The exact source of the error is in breeze.debug.js at line 8597 - constructor of DataProperty.

There the defaultValue has to be set and in my case it tries to get the default value from the property dataType. The dataType at this point looks the following:

{
    name: "Undefined",
    defaultValue: undefined
}

This happens due to a failure in line 7091 - var dataType = DataType.fromEdmDataType(csdlProperty.type);

because csdlProperty looks like:

{
    name: "BehaviourType",
    nullable: undefined
    type: "ODataMetaDataGenerator.BehaviourType"
}

Which of course is not an Edm-Type and thus fails.. Should the underlying type of the enum be used here?