【问题标题】:Why can't I use the Column data annotation with Entity Framework 5?为什么我不能在 Entity Framework 5 中使用 Column 数据注释?
【发布时间】:2013-07-31 07:28:34
【问题描述】:

我想使用Column 数据注释,如下面的示例代码所示,但编译器(以及 IntelliSense)似乎不知道该特定数据注释。我在 Visual Studio 2010 中使用 EF 5。我使用 NuGet 安装了 EF 5。 RequiredMaxLength 注释正在工作。

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Model
{
    public class Destination
    {
        public int DestinationId { get; set; }
        [Required]
        public string Name { get; set; }
        public string Country { get; set; }
        [MaxLength(500)]
        public string Description { get; set; }
        [Column(TypeName="image")]
        public byte[] Photo { get; set; }
        public List<Lodging> Lodgings { get; set; }
    }
}

我错过了什么?

【问题讨论】:

    标签: visual-studio-2010 entity-framework c#-4.0 entity-framework-5 data-annotations


    【解决方案1】:

    列在:

    using System.ComponentModel.DataAnnotations.Schema;
    

    以下代码:

    using System.ComponentModel.DataAnnotations.Schema;
    using System.Data.Entity;
    
    namespace ConsoleApplication2
    {
        public class MyContext : DbContext
        {
            public IDbSet<Entity> Entities { get; set; }
        }
    
        public class Entity
        {
            public int Id { get; set; }
            [Column(TypeName = "image")]
            public byte[] Photo { get; set; }
        }
    }
    

    产生:

    【讨论】:

      猜你喜欢
      • 2018-08-02
      • 2019-09-04
      • 2015-06-14
      • 1970-01-01
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      相关资源
      最近更新 更多