0

私はこの定義を持つクラスを持っています:

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

私の概要とヒントと画像は次のようになります。

 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 と tips を使用したいだけで、データベースに about,Images または tips テーブルを持ちたくありません!

エンティティ フレームワークでは、上記のすべてのクラスをマップするために Id が必要ですが、どうすればよいですか?

4

1 に答える 1

1

here i just want to use about and Images and tips as a helper class to just create a property and don't want to have about,Images or tips table in database

So you are looking for complex type. Mark your About, Tips and Images classes with [ComplexType] attribute.

Entity framework needs Id to map all of above classes , how can I do that ?

EF only needs Id for entities. If you map them as complex types you will not need to use any Id.

Btw. if you don't want to have those classes and their properties in database at all you can use [NotMapped] attribute instead.

于 2013-03-05T08:49:48.483 に答える