是否可以在没有明确重字节[]数据的情况下加载Document实体? [英] Is it possible to load a Document entity without the heavy byte[] data explicitly ?

查看:55
本文介绍了是否可以在没有明确重字节[]数据的情况下加载Document实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


 


我想加载文档数据,如DocumentName和DocumentKeywords,以便在列表中显示它们。但我不想将Document的byte []数据加载到列表中


因为这需要太长时间等等... 


我想在查询Document表时,使用属性注释排除我的数据属性。


 


是吗可能使用CPT5还是计划用于未来版本?

解决方案

Lisa,


 


理想情况下,这可以通过延迟加载数据属性来完成。 
这是我们希望在EF的未来版本中支持的内容,但目前不支持它—仅支持将导航属性延迟加载到其他实体。  
这方面的常见解决方法是映射您的"文档"”表到两个实体—一个实体包含PK和所有非重属性,另一个实体包含PK和byte []数据。 
使用这种方法,第一次访问数据导航属性时,包含大数据的DocumentData实体会被延迟加载。 
这称为表拆分,Code First允许它使用如下代码。 
然而,不幸的是,CTP5有一个令人讨厌的错误,这意味着表拆分不适用于CTP5。 
我们会在发布之前解决这个问题。


 


   
public class
文件


   
{


       
public int Id {
获得; set ; }


       
public string 名称{
获得; set ; }


       
public virtual
DocumentData 数据{ get ;
set ; }


   
}


 


   
public class
DocumentData


   
{


       
public int Id {
获得; set ; }


       
public byte [] Data {
获得; set ; }


   
}


 


   
public class
DocsContext DbContext


< span style ="font-family:Consolas; font-size:9.5pt">    
{


       
public DbSet < 文档>文件{
get ; set ; }


&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;


       
受保护 覆盖
void OnModelCreating( ModelBuilder modelBuilder)


       
{


           
//注意:不适用于CTP5。


          &NBSP;&NBSP;
modelBuilder.Entity< 文档>()。ToTable(" Document" );


< span style ="">           
modelBuilder.Entity< DocumentData >()。ToTable(" Document" );


< span style ="">       
}


   
}


 


谢谢,


亚瑟


Hello,

 

I want to load my documents data like DocumentName and DocumentKeywords to show them in a list. But I do not want to load the Document`s byte[] data into the list

because that would take too long etc... 

I want to exclude maybe with an Attribute annotation that my Data Property is included when I query the Document table.

 

Is that possible with CPT5 or planned for a future version?

解决方案

Lisa,

 

Ideally this would be done by lazy-loading of the data property.  This is something that we would like to support in a future version of EF, but it is not currently supported—only lazy loading of navigation properties to other entities is supported.  The common workaround for this is to map your “Document” table to two entities—one entity contains the PK and all non-heavy properties, the other contains the PK and the byte[] data.  Using this approach the DocumentData entity containing the large data is lazily loaded the first time that the Data navigation property is accessed.  This is called table splitting and Code First allows it using code like the following.  However, unfortunately CTP5 has a nasty bug which means table splitting does not work with CTP5.  We will fix this before we release.

 

    public class Document

    {

        public int Id { get; set; }

        public string Name { get; set; }

        public virtual DocumentData Data { get; set; }

    }

 

    public class DocumentData

    {

        public int Id { get; set; }

        public byte[] Data { get; set; }

    }

 

    public class DocsContext : DbContext

    {

        public DbSet<Document> Documents { get; set; }

       

        protected override void OnModelCreating(ModelBuilder modelBuilder)

        {

            // Note: Does not work with CTP5.

            modelBuilder.Entity<Document>().ToTable("Document");

            modelBuilder.Entity<DocumentData>().ToTable("Document");

        }

    }

 

Thanks,

Arthur


这篇关于是否可以在没有明确重字节[]数据的情况下加载Document实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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