一千萬個為什麽

搜索

實體框架復雜類型與創建新實體

我正在閱讀有關Entity Framework 4.0的內容,我想知道為什麽要創建復雜類型而不是新實體(表)以及它們之間的關系?

最佳答案

The perfect example is an address. Using a complex type for an address is much easier to deal with than a new entity. With complex types you do not have to deal with the Primary Key. Think about accessing an address how many common types of entities would have an address (Business Units, People, Places). Imagine populating many peoples addresses and needing to set a key for each one. With complex types you simply access the internal properties of they type and you're done. Here is an MSDN link of an example. http://msdn.microsoft.com/en-us/library/bb738613.aspx

轉載註明原文: 實體框架復雜類型與創建新實體