EF4 Code 首先从哪些信息构建概念模型
据我了解,Code First 正在构建一个在内存中使用 EF4 的模型,您可以在其中微调您的映射和内容。
该模型是基于什么信息构建的?
您会看到,我有一个现有的应用程序,并且希望首先将我们的 DAL 更改为代码,但我想一点一点地完成。所以我有一个像这样的 Context 类:
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 会抱怨。但我不希望它们出现在我的 EF 模型中。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它从流畅映射和映射实体本身获取信息。因此,如果您的 JournalEntity 包含返回其他实体的属性,我认为 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.