延迟在Entity Framework v.1中加载昂贵的字段 [英] Delay loading expensive fields in Entity Framework v.1

查看:93
本文介绍了延迟在Entity Framework v.1中加载昂贵的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网上狩猎之后,想到我会想出这个解决方案,我似乎已经碰到了另一块砖墙。



我在我的桌子上数据库:照片;包含用于PhotoID,Caption,Ordering和四组二进制数据的列:原始,大,中和小(是的,它是基于具有各种修复程序的旧ASP.NET入门工具包等)。



我正在从L2S转移到实体框架,以获得一些优势,所以我不再需要通过一个PhotosTags属性来获取标签贴在照片上,例如,但我正在寻找一种延迟加载二进制数据的方法 - 大多数时候,我只需要标题,标签和ID,然后将它们移交到另一个区域,以获得用户实际查看图像时的二进制数据。



我已经看了以下帖子:


  1. 如何拆分数据表?

  2. 表拆分:将多个实体类型映射到同一个表格

  3. 第7章:实体框架学习指南(7.1延迟加载昂贵的领域)

最后我结束了一个这样的实体映射:



实体图http://www.doodle.co .uk // UserFiles / Image / EF-LazyLoad.png



而且,根据上面的链接,我修改了edmx文件以包含以下引用约束:

 <参考证明> 
< Principal Role =照片>
< PropertyRef Name =PhotoID/>
< / Principal>
<从属角色=PhotoDetails>
< PropertyRef Name =PhotoID/>
< / Dependent>
< / ReferentialConstraint>

该模型验证但不构建 - 因为标签映射的问题我认为:


错误3019:从行871,892开始的映射片段中的问题:复合键列的映射不正确。外键约束'FK_siteContent_TagsPhotos_siteContent_Photos'从表siteContent_TagsPhotos(PhotoID)到表siteContent_Photos(PhotoID):表中的列(PhotoID)siteContent_TagsPhotos被映射到siteContent_Tags中的属性(PhotoID)在表siteContent_Photos中的照片和列(PhotoID)映射到属性(PhotoID)在PhotosPhotoDetails。通过映射的列顺序不会保留。


从照片到标签的关系是通过一个链接表,列号为PhotoID, TagID。



有没有人设法获得这些建议,或者类似的,可以使用.NET 3.5 SP1中的Entity Framework与这样的数据结构?或者你可以指出我的GoogleFU的局限性吗?



我知道这将在.NET 4中更容易,但这不是在这里,它可能会一段时间后,我的主机开始提供安装在某个地方。



谢谢。

解决方案

我遇到同样的问题,而我尚未找到3.5SP1的解决方案,我确认此错误消失为EF 4.0。



实际上,您的一个潜在的解决方法是在PhotoDetails实体中为主键使用不同的字段。


After hunting around the net, and thinking I'd come up with the solution, I seem to have hit another brick wall.

I have a table in my database: Photos; containing columns for PhotoID, Caption, Ordering, and four sets of binary data: Original, Large, Medium and Small (yes, it was based on the old ASP.NET starter kit with various fixes, etc).

I'm in the process of moving from L2S to Entity Framework for some of the advantages I appear to get with that - so I no longer need to go through a PhotosTags property to get the list of Tags attached to a photo for example, but I'm looking for a way to delay loading the binary data - most of the time, I only need caption, tag, and ID, and I then hand these off to another area to get the binary data when a user actually views the image.

I've taken a look at the following posts:

  1. How to split a data table?
  2. "Table Splitting": Mapping multiple entity types to the same table.
  3. Chapter 7 of: Entity Framework Learning Guide (7.1 Delay loading of expensive fields)

And I ended up with an Entity Mapping looking like this:

Entity Diagram http://www.doodle.co.uk//UserFiles/Image/EF-LazyLoad.png

And, as per the links above, I modified the edmx file to include the following Referential Constraint:

<ReferentialConstraint>
  <Principal Role="Photos">
    <PropertyRef Name="PhotoID" />
  </Principal>
  <Dependent Role="PhotoDetails">
    <PropertyRef Name="PhotoID" />
  </Dependent>
</ReferentialConstraint>

The model validates, but doesn't build - because of an issue with the Tags mapping I think:

Error 3019: Problem in Mapping Fragments starting at lines 871, 892: Incorrect mapping of composite key columns. Foreign key constraint 'FK_siteContent_TagsPhotos_siteContent_Photos' from table siteContent_TagsPhotos (PhotoID) to table siteContent_Photos (PhotoID): Columns (PhotoID) in table siteContent_TagsPhotos are mapped to properties (PhotoID) in siteContent_TagsPhotos and columns (PhotoID) in table siteContent_Photos are mapped to properties (PhotoID) in PhotosPhotoDetails. The order of the columns through the mappings is not preserved.

The relationship from Photos to Tags is through a link table, columns PhotoID, TagID.

Has anyone managed to get either those recommendations, or something similar, to work with the Entity Framework in .NET 3.5 SP1 with a data structure like this? Or can you point out the limitations of my GoogleFU?

I know that this will all be much easier in .NET 4, but that's not here, and it will probably be a while after it's released that my host starts offering to install it somewhere.

Thanks.

解决方案

I've hit the same issue and while I haven't found a solution for 3.5SP1 I did confirm that this error goes away with EF 4.0.

Actually, a potential workaround for you would be to use a different field for the primary key in your PhotoDetails entity.

这篇关于延迟在Entity Framework v.1中加载昂贵的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆