Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6728277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:09:04+00:00 2026-05-26T10:09:04+00:00

I have 2 entities. public class Foo { public virtual int FooId {get; set;

  • 0

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");
                         });
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:09:04+00:00Added an answer on May 26, 2026 at 10:09 am

    I refactored your code a bit but I can’t see your problem.

    public class Foo
    {
        public Foo()
        {
            Bars = new List<Bar>();
        }
    
        #region Public Properties
    
        public virtual IList<Bar> Bars { get; set; }
    
        public virtual DateTime Date { get; set; }
    
        public virtual int FooId { get; set; }
    
        #endregion
    }
    
    public class Bar
    {
        #region Public Properties
    
        public virtual int BarId { get; set; }
    
        public virtual DateTime Date { get; set; }
    
        public virtual IList<Foo> Foos { get; set; }
    
        public virtual byte[] Value { get; set; }
    
        #endregion
    }
    
    public class FooConfiguration : EntityTypeConfiguration<Foo>
    {
        public FooConfiguration()
        {
            HasKey(m => m.FooId);
    
            HasMany(m => m.Bars)
                    .WithMany(l => l.Foos)
                    .Map(m =>
                        { 
                            m.ToTable("FooBars");
                            m.MapLeftKey(f => f.FooId, "FooId");
                            m.MapRightKey(b => b.BarId, "BarId");
                        });
        }
    }
    public class BarConfiguration : EntityTypeConfiguration<Bar>
    {
        public BarConfiguration()
        {
            HasKey(m => m.BarId);
        }
    }
    

    When I do this I get the byte[] back from the database

    using(var context = new FooBarContext())
            {
                var foo = new Foo();
                foo.Date = DateTime.Now;
    
                var bar = new Bar();
                bar.Date = DateTime.Now;
                bar.Value = UTF8Encoding.UTF8.GetBytes("string");
    
                foo.Bars.Add(bar);
    
                context.Foos.Add(foo);
    
                context.SaveChanges();
            }
    
            using(var context = new FooBarContext())
            {
                var foos = context.Foos.Where(f => f.FooId == 1).ToList();
            }
    

    Make sure you are using the latest of EF.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following entities: public class Product { [Key] public int Id{get;set;} //other properties
I have two entities: public class Parent() { public ICollection<Child> Children { get; set;
Consider: class Foo { public string Name{get;set;} public string[] WebSites{get;set;} } I have a
I have the following entities public abstract class Card { public virtual int Id
I have two entities: public class Product { [HiddenInput(DisplayValue=false)] public int ProductID { get;
i have the following entities: public class Category { public virtual int CategoryID {
I have following two entities public class User { public int UserId { get;
I have 2 entities: public class Authority : Entity { [NotNull, NotEmpty] public virtual
I have the following two entities: public class Entity1 { public IList e2 {
I have two entities: @Entity public class File ....... @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.