문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top