I have a varbinary(max) field in one of my tables but I don't need it every time and I'm looking for a way to fetch it from the database only when necessary. I'm using ADO.NET Entity Framework. How to do that?
The solution was to create a separate table with the varbinary field and make 1-to-1 relationship between the tables
It is not necessarily to create separate table. You should do several steps. Let's assume that we have table 'Documents' (Id, Name, Data (varbinary)).
Now build the project.
NOTE. Now when creating new 'Document' entity you should also create new 'DocumentData' entity even if you don't want to place any data yet:
Document doc = new Document();
doc.Name = "My document";
doc.DocumentData = new DocumentData();
context.Documents.Add(doc);
context.SaveChanges();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With