Print Page | Close Window

StringLengthVerifier attribute with CF Migration

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3347
Printed Date: 05-Apr-2025 at 1:52am


Topic: StringLengthVerifier attribute with CF Migration
Posted By: Walid
Subject: StringLengthVerifier attribute with CF Migration
Date Posted: 20-Mar-2012 at 3:36am
Hi,

In the doc  http://drc.ideablade.com/xwiki/bin/view/Documentation/code-first-entity-classes - http://drc.ideablade.com/xwiki/bin/view/Documentation/code-first-entity-classes  it is recommended to use the StringLengthVerifier attribute with CF class.

The problem is this attribute is totally ignored while using CF Migration. So I find myself having to duplicate those information in the Fluent API to be sure the fields will have the required size etc ...

Is this a bug or a normal behavior ?  I can't imagine duplicate this information on all the entities ...


regards 



Replies:
Posted By: DenisK
Date Posted: 20-Mar-2012 at 3:19pm
Hi Walid,

Do you mean that the StringLengthVerifierAttribute gets ignored when you run the "Add-Migration" command from your Package Manager Console?

If so, this is expected and outside of DevForce control as Add-Migration is an Entity Framework method and as such it can only recognize the attributes that it knows. And I'm guessing it only recognize attributes listed in http://msdn.microsoft.com/en-us/library/gg197525%28v=vs.103%29.aspx - Code First Data Annotations .

If you want to use DevForce Verifier attributes, and if it were me, I would do the following steps:

1. Use EF Code First attributes first to build the migration scaffolding
2. Run migration and update the database
3. Use  http://drc.ideablade.com/xwiki/bin/view/Documentation/code-second - DevForce Code Second  to help generate the new entities and their properties complete with DevForce Verifier attributes.

It's not quite as straightforward but it's an option. Hopefully someone smarter than me can chime in :)


Posted By: Walid
Date Posted: 21-Mar-2012 at 1:55am
Thank Denisk, 

I will investigate your solution.

That might also help me solving my problem with CF Migration and the need of multiple Model, because actually I can't find the best way to do it !!





-------------



Print Page | Close Window