static void TestPhotographs() { byte[] thumbBits = new byte[100]; byte[] fullBits = new byte[2000]; using (var context = new PhotographContext()) { var photo = new Photograph { Title = "My Cat", ThumbnailBits = thumbBits }; var fullImage = new PhotographFullImage { HighResolutionBits = fullBits }; photo.PhotographFullImage = fullImage; context.Photographs.Add(photo); context.SaveChanges(); } using (var context = new PhotographContext()) { foreach (var photo in context.Photographs) { Console.WriteLine("Photo: {0}, ThumbnailSize {1} bytes", photo.Title, photo.ThumbnailBits.Length); context.Entry(photo) .Reference(p => p.PhotographFullImage).Load(); Console.WriteLine("Full Image Size: {0} bytes", photo.PhotographFullImage.HighResolutionBits.Length); } } }
private static void TestPhotograph() { AddPhoto(); using var context = new PhotographContext(); foreach (var photo in context.Photographs) { Console.WriteLine("Photo: {0}, ThumbnailSize {1} bytes", photo.Title, photo.ThumbnailBits.Length); context.Entry(photo).Reference(p => p.PhotographFullImage).Load(); Console.WriteLine("Full Image Size: {0} bytes", photo.PhotographFullImage.HighResolutionBits.Length); } }
public void Print() { using (var context = new PhotographContext()) { foreach (var photo in context.PhotographSet) { 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 Add() { var thumbBits = new byte[100]; var fullBits = new byte[2000]; using (var context = new PhotographContext()) { var photo = new Photograph { Title = "My Dog", ThumbnailBits = thumbBits }; var fullImage = new PhotographFullImage { HighResolutionBits = fullBits }; photo.PhotographFullImage = fullImage; context.PhotographSet.Add(photo); context.SaveChanges(); } }
private static void AddPhoto() { byte[] thumbBits = new byte[100]; byte[] fullBits = new byte[2000]; using var context = new PhotographContext(); var photo = new Photograph { Title = "My Dog", ThumbnailBits = thumbBits }; var fullImage = new PhotographFullImage { HighResolutionBits = fullBits }; photo.PhotographFullImage = fullImage; context.Photographs.Add(photo); context.SaveChanges(); }