0

我有以下类,我用 [NotMapped] 属性标记了所有非基元。然而它继续给我以下错误:

我在用:

  • VS 2010 SP1
  • .Net 4.0 (C#) - WinForms
  • 实体框架 5.0 代码优先
  • SQL 紧凑型 (CE) 3.5

The type 'MySolution.Core.Blob' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject.

[System.ComponentModel.DataAnnotations.Schema.Table("Blob")]
public partial class Blob
{
    [System.ComponentModel.DataAnnotations.Schema.NotMapped]
    private AForge.Imaging.Blob BlobInternal { get; set; }

    public Blob ()
    {
        this.BlobInternal = new AForge.Imaging.Blob(0, new System.Drawing.Rectangle());
    }

    public Blob (int id, System.Drawing.Rectangle rect)
    {
        this.BlobInternal = new AForge.Imaging.Blob(id, rect);
    }

    public Blob (AForge.Imaging.Blob source)
    {
        this.BlobInternal = new AForge.Imaging.Blob(source);
    }

    [System.ComponentModel.DataAnnotations.Schema.Column("OriginalSize")]
    public bool OriginalSize { get { return (this.BlobInternal.OriginalSize); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("Id")]
    public int Id { get { return (this.BlobInternal.ID); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("Area")]
    public int Area { get { return (this.BlobInternal.Area); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("Fullness")]
    public double Fullness { get { return (this.BlobInternal.Fullness); } }

    [System.ComponentModel.DataAnnotations.Schema.NotMapped]
    public AForge.Point CenterOfGravity { get { return (this.BlobInternal.CenterOfGravity); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("CenterOfGravityX")]
    public float CenterOfGravityX { get { return (this.BlobInternal.CenterOfGravity.X); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("CenterOfGravityY")]
    public float CenterOfGravityY { get { return (this.BlobInternal.CenterOfGravity.Y); } }

    [System.ComponentModel.DataAnnotations.Schema.NotMapped]
    public System.Drawing.Rectangle Rectangle { get { return (this.BlobInternal.Rectangle); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("RectangleX")]
    public int RectangleX { get { return (this.BlobInternal.Rectangle.X); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("RectangleY")]
    public int RectangleY { get { return (this.BlobInternal.Rectangle.Y); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("RectangleW")]
    public int RectangleW { get { return (this.BlobInternal.Rectangle.Width); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("RectangleH")]
    public int RectangleH { get { return (this.BlobInternal.Rectangle.Height); } }

    [System.ComponentModel.DataAnnotations.Schema.NotMapped]
    public System.Drawing.Color ColorMean { get { return (this.BlobInternal.ColorMean); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("ColorMeanA")]
    public byte ColorMeanA { get { return (this.BlobInternal.ColorMean.A); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("ColorMeanR")]
    public byte ColorMeanR { get { return (this.BlobInternal.ColorMean.R); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("ColorMeanG")]
    public byte ColorMeanG { get { return (this.BlobInternal.ColorMean.G); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("ColorMeanB")]
    public byte ColorMeanB { get { return (this.BlobInternal.ColorMean.B); } }

    [System.ComponentModel.DataAnnotations.Schema.NotMapped]
    public System.Drawing.Color ColorStdDev { get { return (this.BlobInternal.ColorStdDev); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("ColorStdDevA")]
    public byte ColorStdDevA { get { return (this.BlobInternal.ColorStdDev.A); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("ColorStdDevR")]
    public byte ColorStdDevR { get { return (this.BlobInternal.ColorStdDev.R); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("ColorStdDevG")]
    public byte ColorStdDevG { get { return (this.BlobInternal.ColorStdDev.G); } }

    [System.ComponentModel.DataAnnotations.Schema.Column("ColorStdDevB")]
    public byte ColorStdDevB { get { return (this.BlobInternal.ColorStdDev.B); } }

    [System.ComponentModel.DataAnnotations.Schema.NotMapped]
    public AForge.Imaging.UnmanagedImage Image { get { return (this.BlobInternal.Image); } }
}
4

1 回答 1

1

如果要在 SQL CE 中使用 EF Code Fisrt,则需要为其配置 ConectionFactory。

您可以看到使用 SQL CE 运行 EF 的唯一行是:

Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.3.5");

可以在 MSDN Gallery中下载的示例

于 2013-02-08T17:56:42.740 回答