开发者

MVC3 MvcScaffolding EF SqlCE SqlExpress - NO WORKY!

Not quite sure what's going on here but it seems as though Microsoft always comes out with the coolest frameworks (in theory) and then leaves no support. Anyone out there that can help me I will be VERY greatful. This one has had me stumped for two days now and I still cannot figure it out. Here's the setup:

  1. Visual Studio 2010 Professional (or Express for that matter, I've tried both)
  2. SQL Server Compact Edition 4 (or Express for that matter, I've tried both)
  3. Create New Project, add new model (I called mine BlogModels.cs)
  4. Add a new class called Post and give it properties as shown below...

    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System开发者_C百科.Data.Entity;
    using System.ComponentModel.DataAnnotations;
    
    namespace MVC3BlogEngine.Models
    {
        public class Post
        {
            public int ID { get; set; }
            [Required]
            public string Title { get; set; }
            [Required]
            [DataType(DataType.MultilineText)]
            public string Text { get; set; }
            public DateTime PublishDate { get; set; }
        }
    }
    
  5. Run project, browse to model (/Posts) and attempt to add a new post. If I enter more than say 128 characters, an exception is thrown:

    Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

So, what gives? I go look at the database that it created (which I think is the coolest thing since sliced bagels) and see that the column that it created was a nvarchar(128). So, my first thought was that even though I told it to use MultilineText as the datatype, it didn't generate a column properly (not good MS). So, I changed the datatype to text and tried again. No luck.

Anyone?


Well, it would seem that at last resort of removing the attribute of the datatype resolved the issue. The only reason I had it in there to start with was because of Scott Hanselman's video blog entry on creating an MVC3 Blog and he used the attribute in his example (November 2010) and MVC3 was still in development. So, FYI, DataType.MultilineText will not allow you to enter over 128 characters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜