This is a migrated thread and some comments may be shown as answers.

how to get size of a database column

1 Answer 66 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Remco
Top achievements
Rank 1
Remco asked on 14 Mar 2014, 08:56 AM
Hello,

i get the following error:

DataStoreException: Update failed: Telerik.OpenAccess.RT.sql.SQLException: String or binary data would be truncated.

My database look like this:

varchar(31) Name;
varchar(31) FirstName;

and the generated Enty Model is

string Name;
string FirstName;

if i try to save a Name with longer a longer size i get the exception.

- how can i get the possible size of a colum / field?  
So that i can do some checks like = Name = value.SubString(0, sizeofColumn(Name))

thanks for any tip in advance









1 Answer, 1 is accepted

Sort by
0
Accepted
Ralph Waldenmaier
Telerik team
answered on 14 Mar 2014, 12:41 PM
Hi remco,
You can obtain the length of a particular column via the metadata.
See the following example:
var type = ((Telerik.OpenAccess.OpenAccessContextBase)(ctx)).Metadata.PersistentTypes.First(x => x.Name.Equals("YOURCLASSNAME"));
var length = type.Table.Columns.First(x => x.Name.Equals("YOURCOLUMN")).Length;

This will allow you to check the input values and avoid such errors.

Feel free to ask in case you have any other question.

Regards,
Ralph Waldenmaier
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
General Discussions
Asked by
Remco
Top achievements
Rank 1
Answers by
Ralph Waldenmaier
Telerik team
Share this question
or