KB Article A2728
Visible to All Users

How to increase the text field size of a persistent object

Description:
My object (the XPObject descendant) has a persistent string field. I've noticed that the field size is limited to 100 characters, but I need to store longer text in this field. I have played with the DbType attribute, but could not find the correct syntax to increase the field size. I'm using the MS Access database as a persistent storage.

Answer:
100 characters is the default size of a text property in XPO. It can be changed by adding the Size or DbType attribute to the property's declaration.
DbType arguments are passed to the CREATE TABLE SQL query "as-is". Therefore you should check your database server's SQL syntax for the allowed data types. Thus, MS Access accepts the "varchar(n)" string as a column type. n is an integer value between 1 and 255. If you want XPO to create a longer text column in MS Access, you should use the "LONGTEXT" keyword. Here is some sample code:

C#
string _lastName; [DbType("varchar(200)")] public string LastName { get { return _lastName; } set { SetPropertyValue("LastName", ref _ lastName, value); } } string _longMemo; [DbType("LONGTEXT")] public string LongMemo { get { return _longMemo; } set { SetPropertyValue("LongMemo", ref _longMemo, value); } }

We advise you against using the DbType attribute since its value is a database type dependent. That is, if you decide to use a different database server as the data store, you will need to change all the DdType attributes. It's best to use the Size attribute instead. In this case, XPO automatically decides which server data type to use to store your object's property.

C#
// the same as varchar(255) // displayed as "Text" in the MS Access table designer string _firstName; [Size(255)] public string FirstName { get { return _firstName; } set { SetPropertyValue("FirstName", ref _ firstName, value); } } // the same as LONGTEXT // displayed as "Memo" in the MS Access table designer string _companyName; [Size(500)] public string CompanyName { get { return _companyName; } set { SetPropertyValue("CompanyName", ref _companyName, value); } }

You can use the Size attribute with the SizeAttribute.Unlimited parameter to create a property of the maximum size supported by your database server.

C#
string _notes; [Size(SizeAttribute.Unlimited)] public string Notes { get { return _notes; } set { SetPropertyValue("Notes", ref _notes, value); } }

Note. The Size attribute is ignored when the DbType is used.
See Also:
SizeAttribute
How to log the SQL queries made by XPO
How does XPO support the delayed loading of objects and properties?

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.