private static void Problema3() { byte[] thumbBits = new byte[100]; byte[] fullBits = new byte[2000]; using (var context = new PhotoContext()) { var photo = new Photograph { Title = "My Dog", ThumbnailBits = thumbBits }; var fullImage = new PhotographFullImage { HighResolutionBits = fullBits }; photo.PhotographFullImage = fullImage; context.Photographs.Add(photo); context.SaveChanges(); } using (var context = new PhotoContext()) { foreach (var photo in context.Photographs) { Console.WriteLine("Photo: {0}, ThumbnailSize {1} bytes", photo.Title, photo.ThumbnailBits.Length); // explicitly load the "expensive" entity, context.Entry(photo) .Reference(p => p.PhotographFullImage).Load(); Console.WriteLine("Full Image Size: {0} bytes", photo.PhotographFullImage.HighResolutionBits.Length); } } }
public void Function() { byte[] thumbBits = new Byte[100]; byte[] fullBits = new Byte[2000]; using (var context = new Scenariu3Context()) { var photo = new Photograph() { Title = "My Dog", ThumbnailBits = thumbBits }; var fullImage = new PhotographFullImage { HighResolutionBits = fullBits }; photo.PhotographFullImage = fullImage; context.Photographs.Add(photo); context.SaveChanges(); foreach (var photograph in context.Photographs) { Console.WriteLine("Photo: {0}, ThumbnailSize {1} bytes", photograph.Title, photograph.ThumbnailBits.Length); context.Entry(photograph).Reference(p => p.PhotographFullImage).Load(); Console.WriteLine("Full Image Size: {0} bytes", photograph.PhotographFullImage.HighResolutionBits.Length); } } }