0

我有这个定义的类:

public class WebSiteContent 
    {
        public Guid Id { get; set; }
        public About About { get; set; }
        public Tips Tips { get; set; }
        public Images Images { get; set; }
    }

我的 About 和 Tips 和 Images 看起来像这样:

 public class About
    {
        public Guid Id { get; set; }
        public string Text { get; set; }
        public string Addres { get; set; }
        public int PhoneNumber { get; set; }
        public int Mobile { get; set; }
    }

和提示:

 public class Tips
    {
        public Guid Guid { get; set; }
        public string Content { get; set; }
    }

和图像:

public class Images
    {
        public Guid Id { get; set; }
        public string Background { get; set; }
        public string Logo { get; set; }
        public About About { get; set; }

    }

在这里,我只想使用 about 和 Images and Tips 作为帮助类来创建一个属性,并且不想在数据库中拥有 about、Images 或 Tips 表!

实体框架需要 Id 来映射上述所有类,我该怎么做?

4

1 回答 1

1

在这里,我只想使用 about 和 Images and Tips 作为帮助类来创建一个属性并且不想在数据库中拥有 about、Images 或 Tips 表

所以你正在寻找复杂的类型。[ComplexType]用属性标记您的 About、Tips 和 Images 类。

实体框架需要 Id 来映射上述所有类,我该怎么做?

EF 只需要实体的 ID。如果将它们映射为复杂类型,则不需要使用任何 Id。

顺便提一句。如果您根本不想在数据库中拥有这些类及其属性,则可以改用[NotMapped]属性。

于 2013-03-05T08:49:48.483 回答