开发者

From what information is EF4 Code first building the conceptual model

开发者 https://www.devze.com 2023-02-13 05:13 出处:网络
As I understand Code First is building a model to work with EF4 in memory and where you can fine tune your mappings and stuff.开发者_运维技巧

As I understand Code First is building a model to work with EF4 in memory and where you can fine tune your mappings and stuff.

开发者_运维技巧

Based on what information is this model being build?

You see I have an existing application and am looking to change our DAL to code first, but I want to do it piece by piece. So I have a Context class like this:

Public Class JournalContext
    Inherits DbContext

    Public Sub New()
        MyBase.New("AppDb")
    End Sub

    Public Property JournalEntries As IDbSet(Of JournalEntry)

    Protected Overrides Sub OnModelCreating(ByVal modelBuilder As System.Data.Entity.ModelConfiguration.ModelBuilder)

        modelBuilder.Entity(Of JournalEntry).Property(Function(e) e.Id).HasColumnName("JournalEntryId")
    End Sub

End Class

EF is complaining when I use this class about other Entity types that has no key defined. But I don't want them to be in my model for EF.


It takes information from fluent mapping and mapped entity itself. So if your JournalEntity contains properties which returns other entities, I think EF will try to map them unless you explicitly exclude them from mapping.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号