public static void Scenariu3() { byte[] thumbBits = new byte[100]; byte[] fullBits = new byte[2000]; using (var context = new Scenariu3()) { var photo = new Photograph { Title = "My Dog", ThumbnailBits = thumbBits }; var fullImage = new PhotographFullImage { HighResolutionBits = fullBits }; photo.PhotographFullImage = fullImage; context.Photos.Add(photo); context.SaveChanges(); } using (var context = new Scenariu3()) { foreach (var photo in context.Photos) { 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); } } }
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); } } }
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(); }