make byte []属性加载懒惰 [英] make byte[] property load lazy

查看:111
本文介绍了make byte []属性加载懒惰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 EF4 Code First ,我有一个属性:

I'm using EF4 Code First and I have a property:

public byte[] Bytes {get;set;}

我可以让这个属性加载懒洋洋(只有在需要的时候) ?

can I make this property load lazily ( only when it's needed) ?

推荐答案

EF 4.1 RC中的表拆分工作:

Table spliting works in EF 4.1 RC:

public class Item
{
    public int Id { get; set; }
    ...
    public virtual ItemDetail ItemDetail { get; set; }
}

public class ItemDetail
{
    public int Id { get; set; }
    public byte[] Bytes { get; set; }
}

public class Context : DbContext
{
    public DbSet<Item> Items { get; set; }
    public DbSet<ItemDetail> ItemDetails { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<Item>().ToTable("Items");
        modelBuilder.Entity<ItemDetail>().ToTable("Items");
        modelBuilder.Entity<Item>()
            .HasRequired(i => i.ItemDetail)
            .WithRequiredPrincipal();
    }
}

这篇关于make byte []属性加载懒惰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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