Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: Table TestTable not found #6

Open
nsulikowski opened this issue Apr 27, 2014 · 14 comments
Open

Exception: Table TestTable not found #6

nsulikowski opened this issue Apr 27, 2014 · 14 comments

Comments

@nsulikowski
Copy link

I can't figure out why:

dynamic db = Database.Opener.Open("http://nsuli.com/odata3/us/");
IEnumerable products = db.TestTable.All();

@object
Copy link
Member

object commented Apr 27, 2014

Thank you for the report. I tested your service and noticed that comparing to other OData feeds it lacks property m:IsDefaultEntityContainer="true" in entity set definition. I will check the specification, and if there is no requirement for a default entity container, I will make a fix and let you know.

@object
Copy link
Member

object commented Apr 27, 2014

I have made a small fix in Simple.OData.Client (a package that Simple.Data.OData uses), so now it longer requires m:IsDefaultEntityContainer="true" in the entity set definition. However, it still fails to read TestTable content due to a different problem. If you look at entry XML, here is how it looks:

<entry>
<id>0</id>
<category term="nsuli_com.Type_TestTable" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<title />
<updated>2014-04-27T20:08:17Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:DateS m:type="Edm.DateTime">2014-01-02T00:00:00</d:DateS>
<d:Value m:type="Edm.Double">1.2</d:Value>
</m:properties>
</content>
</entry>

Note that the "id" is set to "0". But the "id" is the entity key, and according to the schema the key property is DateS, so the "id" should be set to the same value as DateS. Moreover, according to the OData specification, "the "atom:id" element conveys a permanent, universally unique identifier for an entry or feed." Here's an example of entry "id" from a sample service:

<id>http://services.odata.org/V3/OData/OData.svc/Products(0)&lt;/id>

So it seems to me that the entry XML doesn't fully follow OData spec. How did you build your OData service? DId you write your own feed generation code or you used some other tools?

@nsulikowski
Copy link
Author

Hi. I also fixed the IsDefaultEntityContainer in my metadata.
Sorry for the errors in my odata. I generate it using ODataLib 5.6.1 (manually... I do not use Entity Framework). But I've been struggling quite a bit to get all the pieces right.
Now, you say that the entity id is the key. what do you do when the key involves several properties?
Also, do I understand you correctly that the id should look like an url:
http://services.odata.org/V3/OData/OData.svc/Products(0)
only in atom, but in json it should actually contain the key values?
Thanks for your help.

@object
Copy link
Member

object commented Apr 28, 2014

Hi,

I asked Microsoft's Michael Pizzo, and he explained that in V4 the requirements relaxed:

"In OData, the entity id is supposed to be a URI that uniquely identifies the entity. In V4 we encourage the use of a URL that can be used to retrieve the entity, but that's not required. The id is opaque to the client and need not contain the key value(s)."

So in fact your format is correct according to V4 protocol although it may create problems for some clients (like mine :-)). I will try to make a fix asap, but in the meantime if you want to make it work with current version of Simple.Data OData adapter, you have to changes entity "id" according to the old specs.

Here's what you can do.

  1. For entities with single property keys you need to include only key value, e.g.:
    <id>http://services.odata.org/Northwind/Northwind.svc/Orders(10248)&lt;/id>
  2. For entities with multiple property keys you need to includ property names, e.g.:
    <id>http://services.odata.org/Northwind/Northwind.svc/Order_Details(OrderID=10248,ProductID=11)&lt;/id>

Have a look at the sample service http://services.odata.org/Northwind/Northwind.svc, in particularly at tables Orders and Order_Details that show both cases.

I will leave the issue open and support the latest and more relaxed requirement. But if you want your OData feed compliant with older specs (and supported by more clients), you can change id formatting as I showed.

@nsulikowski
Copy link
Author

Wow... that's a really informative response. Thanks much.
FYI, Here is a stackoverflow answer that helped me fix the IsDefaultEntityContainer problem:
http://stackoverflow.com/questions/23328420/isdefaultentitycontainer-in-odata-metadata/23333983?noredirect=1#23333983
One thing I don't like about the uri id is that it makes the odata payload much heavier (repeating that uri for each entity). However, I'll modify my feed to comply with that suggestion.
Great job with this library!

@nsulikowski
Copy link
Author

I modified my odata endpoint to return urls for id's, but I don't think you are parsing dates in uri odata format correctly. ie:
http://www.nsuli.com/odata3/us/TestTable(datetime'2014-01-04T00:00:00Z')
You adapter throws the exception:
The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.

@object
Copy link
Member

object commented Apr 28, 2014

Thanks, I am will look at it asap. I am planning to release a new version tonight, hopefully this issue will be addressed too.

@nsulikowski
Copy link
Author

Great. FYI, here is a link to some of the primitive data types and how they should be serialized/deserialized in a url: http://www.odata.org/documentation/odata-version-2-0/overview/#AbstractTypeSystem

@object
Copy link
Member

object commented Apr 28, 2014

I just pushed the version 2.1.0 of Simple.OData.Client that should fix parsing datetime literals. I'll appreciate if you test it.

@nsulikowski
Copy link
Author

dynamic db = Database.Opener.Open("http://nsuli.com/odata3/us/");
IEnumerable items = db.TestTable.All();
foreach (var item in items)
{
}
still throws
The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.
this is my packages.config after the upgrade:

<packages>
  <package id="Microsoft.Bcl" version="1.1.7" targetFramework="net45" />
  <package id="Microsoft.Bcl.Async" version="1.0.16" targetFramework="net45" />
  <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
  <package id="Microsoft.Net.Http" version="2.2.13" targetFramework="net45" />
  <package id="Simple.Data.Core" version="0.19.0.0" targetFramework="net45" />
  <package id="Simple.Data.OData" version="1.1.0" targetFramework="net45" />
  <package id="Simple.OData.Client" version="2.1.0" targetFramework="net45" />
</packages>

@object
Copy link
Member

object commented Apr 29, 2014

I have tested against your feed now, and what I see is that you write datetime properties with "Z" suffix, but this is accepted only for "datetimeoffset" properties. If I check the link you sent me, I find the following:

DateTime: datetime’yyyy-mm-ddThh:mm[:ss[.fffffff]]’ NOTE: Spaces are not allowed between datetime and quoted portion. datetime is case-insensitive
Example: datetime’2000-12-12T12:00′

DateTimeOffset: datetimeoffset’’ dateTimeOffsetLiteral = Defined by the lexical representation for datetime (including timezone offset) at http://www.w3.org/TR/xmlschema-2
Example: 2002-10-10T17:00:00Z

AFAIK you shouldn't be using "Z" with datetime fields and this is what's causing the parsing error. Can you please double-check this?

@object
Copy link
Member

object commented Apr 29, 2014

Oops, my bad! Actually I didn't fully merged my changes from a development branch. Now I pushed the version 2.1.1, can you try that? I tested on your feed and it seems to work!

@nsulikowski
Copy link
Author

I fixed the "Z" problem. Your plugin works (before and after my "Z" fix).
FYI, this is the c# code I use to generate the keys in the url:
http://stackoverflow.com/questions/23346073/serialize-value-to-odata
Best

@object
Copy link
Member

object commented Apr 29, 2014

Thanks for the link, it's quite useful. I am planning to replace my internal OData serializer code with ODataLib, but will have to keep home-made serialization until then.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants