I have 2 entities.
public class Foo
{
public virtual int FooId {get; set; }
public virtual IList<Bar> Bars { get; set; }
public virtual DateTime Date { get; set; }
}
public class Bar
{
public virtual int BarId { get; set;}
public virtual byte[] Value { get; set; }
public virtual DateTime Date { get; set; }
public virtual IList<Foo> Foos { get; set; }
}
When I load Foo from the database by FooId, it is completely hydrated, when I navigate to Bar, it has the correct BarId and Date from the database, but Value is always a byte[0].
Why?
The database is a varbinary(300) column.
The value in the database if I do select * from Bar in Management Studio shows
BarId Value Date
1 0x20CF30467ABD 10/19/2011
Thoughts?
My mapping:
public class FooConfiguration : EntityTypeConfiguration<Foo>
{
public FooConfiguration()
{
ToTable("Foo");
HasKey(m => m.FooId);
Property(m => m.Date);
HasMany(m => m.Bars)
.WithMany(l => l.Foos)
.Map(m =>
{
m.ToTable("FooBars");
m.MapLeftKey("FooId");
m.MapRightKey("BarId");
});
}
}
public class BarConfiguration : EntityTypeConfiguration<Bar>
{
public BarConfiguration()
{
ToTable("Bar");
HasKey(m => m.BarId);
Property(m => m.Value);
Property(m => m.Date);
HasMany(m => m.Foos)
.WithMany(l => l.Bars)
.Map(m =>
{
m.ToTable("FooBars");
m.MapLeftKey("BarId");
m.MapRightKey("FooId");
});
}
}
I refactored your code a bit but I can’t see your problem.
When I do this I get the byte[] back from the database
Make sure you are using the latest of EF.