NamesSpaces of schemas not used #bug
Closed this issue · 31 comments
Input
<SchemaName1>
<EntityName>
<SchemaName2>
<EntityName>
Output
public class EntityName
In this case, I will get only one entity, which is an incorrect case of inheritance and navigation (links)
Expected output
namespace SchemaName1
{
public class EntityName
{
}
}
namespace SchemaName2
{
public class EntityName
{
}
}
Can I see the xml metadata file?
Waiting if not available now.
I will try to cut out part of the .edmx file tomorrow.
I updated text.
The xml metafile contain an element named EntityContainer
, which can contain something like:
<EntityContainer Name="NorthwindEntities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true" xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntitySet Name="Categories" EntityType="NorthwindModel.Category"/>
<EntitySet Name="Customers" EntityType="NorthwindModel.Customer"/>
....
</EntityContainer>
Here Customers
has namespace NorthwindModel
-
For the example you show, I suppose that the xml file container include more one namespace, something like:
<EntityContainer Name="NorthwindEntities" ...........> <EntitySet Name="EntityName" EntityType="SchemaName1.EntityName"/> <EntitySet Name="EntityName" EntityType="SchemaName2.EntityName"/> .... </EntityContainer>
Is't right?
- Do the xml file contain more than one container?
<Edmx> <!-- version 3.0 -->
<DataServices>
<Schema ns="Namespace1">
<EntityType Name="Name1"/>
</Schema>
<Schema ns="Namespace2">
<EntityType Name="Name1"/>
</Schema>
</DataServices/>
</Edmx>
Schema intead of EntityContainer
A new version 3.2.0.3 that can fix this issue can be downloaded here
Best regards,
Thank you very much. Tomorrow I will test.
Unfortunly, this will not work.
You read schema once of first container.
https://raw.githubusercontent.com/lobster2012-user/odata_samples/master/v4.xml (sample from msdn)
Took from here an example.
Got classes only from the first schema. Hm
Thanks for the sample data file.
You are correct in your note in the previous comment.
Really Odata v3 is a multi container, but Odata v4 is one and only one container.
I modified the code and generated a code for your sample v4.xml in the attached file.
in your sample, the Schema Namespace="Default"
has no EntityType,
and the container contains an EntitySet of type BookStore.Window
which is not the same as the Window EntityType in the schema 'Schema Namespace="NS"'
So, 'Window EntityType'
, here, may refer to an external Entity, or the sample should contain schema named BookStore.
Is it right?
<Schema Namespace="Default" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityContainer Name="Container">
<EntitySet Name="Windows" EntityType="BookStore.Window" />
</EntityContainer>
</Schema>
I, also, generated a sample with a multi container and multi schema with the generated code using the new version(not uploaded yet).
Kindly, can you review the generated code in the attached file and comment for something wrong in the output.
odata-multi-container-v3.zip
poco-multi-container-v3.cs - all ok
Schema Namespace="Default" has no EntityType, and the container contains an EntitySet of type BookStore.Window
True, not carefully looked.
Is it right? -
It looks like the truth.
v4-xml.cs
Should it be a valid c# code?
I think that v4-xml.cs is valid c# code. Do you find something wrong?
Now
public [BookStore.Color Nullable=False] Color {get;set;}
May be Valid
public BookStore.Color Color {get;set;}
When tracing the type details of the properties (Shape,Color, Point,..), I found that odata client give a silent error (not an exception) like:
"ErrorMessage": "The type 'BookStore.Shape' could not be found."
Type.Definition: BadUnresolvedType:BookStore.Shape
"ErrorMessage": "The type 'BookStore.Color' could not be found."
Type.Definition: BadUnresolvedType:BookStore.Color
That means that the Metadata loose these types and it should not.
But How??
I modified the xml file and replace the namespace of the schema "NS"
with "BookStore"
, then every thing shine like magic :D
I'll give a warning message for such errors (if exist).
Also, this schema is Odata V4 which has one container but may have multi schema.
The attached file have both the modified schema (BookStore instead of NS) and the generated c# code.
Have a look and appreciate your feedback if I missed something.
It looks good.
Apparently there is a typo on MSDN.
Thanks for feedback
I will prepare for a new version.
A new version 3.2.0.7 including fix to this issue can be downloaded from github
Hm. I see invalid code.1 namespace. JsonProperty attributes without 'using namespace' and empty names.
The version pass all unit test and also tested with the following services:
http://services.odata.org/V4/Northwind/Northwind.svc
http://services.odata.org/V3/Northwind/Northwind.svc
http://services.odata.org/V2/Northwind/Northwind.svc
http://services.odata.org/V4/TripPinServiceRW
and the schema that I posted in the previous comment and MS dynamic365 crm service(3000+ entity).
kindly, can you provided me with a sample of the xml schema
only the header of the meta service and a dummy entity one per schema.
The schema may be incompatible with OData standard.
This can help in fixing the error.
The attached file is a new version that can dump error message detail as a json string
, like:
edmTypeReference Error: [
{
"$id": "1",
"ErrorLocation": {
"$id": "2",
"LineNumber": 8,
"LinePosition": 10
},
"ErrorCode": 225,
"ErrorMessage": "The type 'BookStore.Shape' could not be found."
}
]
Invalid Type Reference: BadUnresolvedType:BookStore.Shape
Try it and, if possible, post sample of these errors.
This version is good.
At work then check again.
"https://raw.githubusercontent.com/lobster2012-user/odata_samples/master/v3_multischema.xml?"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated using OData2Poco System.
// Service Url:
// MetaData Version: 1.0
// Generated On: 2019-04-02T20:55:58
// </auto-generated>
//------------------------------------------------------------------------------
//
using System;
using System.IO;
using System.Collections.Generic;
namespace ODataDemo
{
public partial class Supplier
{
public int ID {get;set;} //PrimaryKey not null
public string Name {get;set;}
public int Concurrency {get;set;} // not null
}
public partial class Supplier2 : Supplier
{
public string Code {get;set;}
}
}
namespace ODataDemo2
{
public partial class Supplier
{
public int ID {get;set;} //PrimaryKey not null
public string Name {get;set;}
public int Concurrency {get;set;} // not null
}
public partial class Supplier2 : Supplier
{
public string Code {get;set;}
}
}
Glad that it works as you expect.
Some problems on prod. Can I email my schema to you? (later)
Yes, you can.
My email: moh.hassan20@gmail.com
Hi @lobster,
what about the last version?
Hi, @moh-hassan .With the latest version, everything is bad if we are talking about 3 2 07. Do you get a valid file on output a move without errors and warnings during building?
I sent you a beautiful generated schema :D without errors /warning and a new version 3.2.0.8
I compiled the generated code with zero compilation error in net45,net461 and netstandard2.
Can you check.
Let me know if you have any questions.
Thank. I'll see later.
I reviewed the c# code and the xml schema, the next are some finding:
-
The class:
public partial class RepoTradesListItem : ListItem
has no property as a primary key and inherit from ListItem
-
Its property:
public int? ID {get;set;}
is null and it's not related to the Id property in the parent ListItem.
-
Most classes in the Sharepoint schema has the property Id (not ID) as the Pk
-
The class ListItem, in the xml file, line 989:
<EntityType Name="ListItem" BaseType="SP.SecurableObject" OpenType="true">
and it's generated as:
public partial class ListItem : SecurableObject
The class is generated without PK and it has no PK in the xml schema
but ListItem has the property:
[Required]
public int Id {get;set;} // not null
-
Sharepoint extension.This is an overhead .Need a system with plugins.
I think that the client deserialize the payload based on the schema defined in the xml file and not
referencing any external classes outside the xml, and ListItem is exist.
I think that the schema is generated properly.
We agreed in the last discussion that type will be the fullName including namespace
Do you have any comments related to the generation code?
All ok.
Implemented.