OData Metadata validation: maxlength and nullable

Posts   
 
    
rbrown
User
Posts: 33
Joined: 11-Jun-2008
# Posted on: 19-Aug-2014 15:45:10   

I'm using the Odata service (LLBLGenProODataServiceBase<LinqMetaData>) with a breezejs client. I'm not seeing Nullable/MaxLength attributes in the generated $metadata for string fields. Is that supposed to be supported? I see the Nullable="false" on other fields of other data types, but nothing for strings.

This is happening for all my tables. As an example, note the SourceName column in this SourceEntity.

Table definition:


CREATE TABLE [dbo].[Source](
    [SourceID] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [SourceSiteID] [uniqueidentifier] NULL,
    [SourceName] [varchar](16) NOT NULL,
    [SourceTypeID] [uniqueidentifier] NOT NULL,
    [Description] [varchar](80) NULL,
    [Enabled] [bit] NOT NULL,
    [CreatedBy] [nvarchar](80) NOT NULL,
    [CreatedOn] [datetime] NOT NULL,
    [ModifiedBy] [nvarchar](80) NOT NULL,
    [ModifiedOn] [datetime] NOT NULL,
...(etc)

OData $metadata (Note SourceName does not have nullable or maxlength attribute):


<EntityType Name="SourceEntity">
<Key>
<PropertyRef Name="SourceId"/>
</Key>
<Property Name="SourceId" Type="Edm.Guid" Nullable="false"/>
<Property Name="SourceSiteId" Type="Edm.Guid"/>
<Property Name="SourceName" Type="Edm.String"/>
<Property Name="SourceTypeId" Type="Edm.Guid" Nullable="false"/>
<Property Name="Description" Type="Edm.String"/>
<Property Name="Enabled" Type="Edm.Boolean" Nullable="false"/>
<Property Name="CreatedBy" Type="Edm.String"/>
<Property Name="CreatedOn" Type="Edm.DateTime" Nullable="false"/>
<Property Name="ModifiedBy" Type="Edm.String"/>
<Property Name="ModifiedOn" Type="Edm.DateTime" Nullable="false"/>
...(etc)
</EntityType>

Are these attributes supported, and if so, what do I need to do to enable them?

Thanks, Randy

LLBLGen 4.2, adapter (with manager templates), SQL Server 2008 R2 SP1, .NET 4.0

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 20-Aug-2014 00:30:10   

Isn't the manifest used for proxies? And hence the string type is a reference type and the Nullable flag would mean nothing for it.

(Edit) I've found a close question here: https://aspnetwebstack.codeplex.com/discussions/549284

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 20-Aug-2014 10:53:15   

Walaa's link shows that it's not us, so we can't do much about it. Looking at the code in the OData support classes we ship, I see there's simply no room for specifying that info in the OData metadata classes (in this case ResourceProperty). It doesn't have properties for nullable/length. As string is an object type, it's not definable whether it's nullable or not.

Frans Bouma | Lead developer LLBLGen Pro
rbrown
User
Posts: 33
Joined: 11-Jun-2008
# Posted on: 20-Aug-2014 15:56:39   

Apparently it's some internal magic that EF is doing behind the scenes. I was hoping we could achieve this via some type of attributes (think Data Annotations style) in our model. But maybe that is not possible given the limitations of the metadata resource classes.

Perhaps I could go about this another way - generating the metadata via LLBLGen templates.... Breeze lets us provide the metadata manually, as a js file. So I could just generate this from my llblgen model, with all the validation settings, etc. Do you know if anyone has had any luck with this type of approach?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 22-Aug-2014 09:17:25   

rbrown wrote:

Apparently it's some internal magic that EF is doing behind the scenes. I was hoping we could achieve this via some type of attributes (think Data Annotations style) in our model. But maybe that is not possible given the limitations of the metadata resource classes.

Attributes is of no use, if the client reads the meta-data from the odata service, as the odata service has no room for this meta-data (length/nullable) at least not in v5.x. Not sure whether they've changed it in v6/OData v4, which we don't support (as it requires a breaking change to a newer library which isn't backwards compatible rage )

Perhaps I could go about this another way - generating the metadata via LLBLGen templates.... Breeze lets us provide the metadata manually, as a js file. So I could just generate this from my llblgen model, with all the validation settings, etc. Do you know if anyone has had any luck with this type of approach?

I haven't heard of this particular case, but it might look similar to: http://northwind.mattjcowan.com/

Frans Bouma | Lead developer LLBLGen Pro
rbrown
User
Posts: 33
Joined: 11-Jun-2008
# Posted on: 22-Aug-2014 14:17:49   

Thanks for the input. I will check out the link.

Puser
User
Posts: 228
Joined: 20-Sep-2012
# Posted on: 25-Sep-2014 22:56:45   

Hello RBrown,

A collegue and I are investigating LLBLGen together with Breezejs. I have read about the certain peculiarities of the Web API OData in the breeze docs: http://www.breezejs.com/documentation/odata-server

I can see you stumbled upon these problems seeing your post here and your former post regarding $expand. It is explained in the doc.

We would like to get in touch with you so maybe we could 'team up' our efforts to get this thing going.

Further reading suggest something in the lines of using: 1. server side: EdmBuilder : http://www.breezejs.com/samples/breeze-web-api-odata#BuildEDM 2. server side: SummerBreeze: https://github.com/dotnetricardo/SummerBreeze 3. client side: create or use pre-generated metadata: http://www.breezejs.com/documentation/load-metadata-script

We should also look at the saveBundle and read and handle the EntityInfo objects.

Open my profile for my contact details. I hope to hear from you.

Kind regards NV

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 26-Sep-2014 10:15:24   

@PUser He can't see your email address so I've contacted him and have asked whether it's ok to send you his email address.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 26-Sep-2014 15:39:18   

RBrown contacted, agreed, so contacted PUser on forum email address with RBrown's email address simple_smile Hopefully you can help each other out. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Puser
User
Posts: 228
Joined: 20-Sep-2012
# Posted on: 17-Oct-2014 10:49:22   

Hello Frans,

I just read an old twitter post showing that you would be working on a specific LLBLGen adapter for BreezeJS:

https://twitter.com/wardbell/status/255697637636980739

If so, did you try to make a solution beyond OData? And would you like to share your experiences? simple_smile

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 17-Oct-2014 15:20:04   

I did get started but it took so much effort back then (in general writing yet another metadata provider for breeze) that I didn't continue with it, as there were plans by breeze to use odata anyway.

Not sure whether they can use odata nowadays.

Frans Bouma | Lead developer LLBLGen Pro