Strange problem with Data Annotations

Topics: Troubleshooting
Jan 10, 2014 at 4:44 PM
Edited Jan 10, 2014 at 4:48 PM
I am trying to implement a class in a new module. In one of my model class I have some data annotations I have the both the
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; statements included yet I still get
the a MaxLength not found further down my class I use the [Range] annotation and it does not give an error.

I post this here because this only happens in in my Orchard solution not in my non-Orchard projects. Do Orchard or nHibernate preclude the use of the some of the standard asp.Net or Entity Framework annotations.

Thanks for any help.

edit I am using VS 2013 express with Orchard 1.72
Jan 10, 2014 at 5:21 PM
Looks like I can use [StringLength], but does that imply that I can't connect to a separate database using Entity Framework? I am bring this over from another MVC project and I am hoping to speed up my deployment by having to not tackle as much of the Orchard learning curve at this time? Any thoughts or advice will be appreciated.
Jan 13, 2014 at 3:46 AM
You should be able to use EF, yes. It looks like you're just missing a reference.
Jan 13, 2014 at 3:17 PM
Does Orchard somehow block using System.ComponentModel.DataAnnotations.Schema; ? Reason that I ask is that in my prior project not related to Orchard the VS has no problem with the MaxLength annotation in essentially the same class. In my Orchard module VS cannot reference using System.ComponentModel.DataAnnotations.Schema; or MaxLength while other annotations in the same namespace are referenced and used without issue.

I know you all have bigger fish to fry but this seems very weird.
Thanks again for any insight.
Jan 13, 2014 at 3:36 PM
Looks like retargeting my module to .NET 4.5 did the trick.

Thanks to all
Jan 15, 2014 at 2:56 PM
Retargeting to 4.5 removed the intellisense errors but only until did a full rebuild then they reappeared. Now I have a similar issue

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace AOCharting.Models

and the error

Error 1 The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) C:\Users\Visual Studio 2013\Projects\OrchardAO.1.7.2\src\Orchard.Web\Modules\AOCharting\Models\AppliedOptionsDB.cs 3 19 AOCharting

But of course Entity does exist in in System.Data except inside my orchard module.

I'm clueless
Jan 15, 2014 at 5:16 PM
I never added EntityFramework to the project . One day I'll get it right...