moh-hassan/odata2poco

MaxLength for a String property

Closed this issue · 13 comments

Hi moh-hassan,

It's not an issue but a question: Are you aware of a way to get the maxlength of a string attribute?

It doesn't appear to be in the metadata but I hope I'm overlooking it.

Thanks

Hi @darinvanatta
Can you explain by example.
What do you mean by maxlength of a string attribute?
Do you mean:

         [MaxLength(50)]

I'm writing the object values to a database. I'm dynamically creating the tables so when an property is a string, as shown in the image, I need to create a varchar field in the database but I don't if the string's max length is 5 characters or 5,000 characters.

image

Is there somewhere ODATA stores these max length values?

I will investigate the maxlength of string in OData.

Thank you!

The only thing I've found is this for Dynamics 365 Customer Engagement but doesn't apply to Finance and Operations: https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/mt788314(v=crm.8)

I searched for ContractPersonName but i didn't find in the schema.
Is it the same schema previously processed or other one?

It's another one but there isn't anything special about that class or attributes in my example.

I would need to determine the maxlength for any class attribute which is a string.

I didn't find the maxlength in the schema, it seems that it's in not provided in the schema but odata v4 support it.
Can you check your schema if it included the property maxlength .

The metadata is showing v4 but I search for "maxlength" and don't find anything. Might there be another word used to search for?

image

You can see the metadata here:
https://con813-crm612cf723bbf35af6devaos.cloudax.dynamics.com/data/$metadata

The schema also does not contain it.
I will investigate of adding this feature.

Thanks!

Adding a new feature to support maxlength of string and binary (byte[] )
You can download the new version v3.2.0.17

You can add the attribute [MaxLength(n)] by the option

         -a max

or programmatic

	new PocoSetting()
	{
	  Attributes = new List<string> {"max"}
	}

If the metadata schema of the service include the attribute MaxLength of value >0, then it will be generated as

    [MaxLength(30)]
    public string Title {get;set;}

Awesome! Thanks