The Darkside

Shedding light on things and stuff

 
  Home :: Contact :: Syndication  :: Login
  75 Posts :: 0 Stories :: 49 Comments :: 2 Trackbacks

Ads

Archives

Post Categories

Open Source Projects

Other Blogs

When running unit tests, I often using ActiveRecordStarter.CreateSchema() in my test startups to give me a clean database to work from. Whether or not this should be done by a SQL script or a restore from a backup is for another time.

On one such occasion, I started getting a 'binary or string data would be truncated' error being thrown and on closer inspection, I noticed it was because of a certain column that was originally nvarchar (max) by design, but had been recreated by ActiveRecord as nvarchar (255).

A quick Google found many folks having this problem and the solutions varied from changing the data type to NTEXT or StringClob, to setting the length of the field to Int32.Max,however, none of them were directly solving the issue at hand.

The easiest way to remedy this is to make use of the SqlType parameter in the Property attribute of ActiveRecord when declaring your properties. 

[Property("DataField", ColumnType="String", NotNull=true, SqlType = "nvarchar (max)")]
public virtual string Data { get ; set; }

Now, when you call ActiveRecord.CreateSchema(), the column will be created correctly.

posted on Tuesday, December 09, 2008 7:32 AM
Comments have been closed on this topic.