you use the dbcontext to get the underlying connection, then use the connection with the sample code.
var connection = dbContext.Database.GetConnection();
you can use EF to create the row and get the rowid for the SqliteBlob() call
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to setup an Azure Function in .NET 8 Isolated with a Blob Trigger to read/write to Sqlite files as they're uploaded to the blob.
My issue currently, is I can't seem to figure out how to connect the Function's [BlobTrigger(~)] Stream stream
argument to the EF DbContext
.
When I search for this, the most common thing to come up is the Blob I/O for making an SqliteBlob stream, but that takes a connection string, which isn't given from the Function arguments, and doesn't have an option to create the object using another Stream object. Also even if I'm able to make an SqliteBlob object, I'm still not sure on how that would connect to the DbContext
.
Here are my cs files I have so far for this (the .anki2 file extension is the Sqlite file):
you use the dbcontext to get the underlying connection, then use the connection with the sample code.
var connection = dbContext.Database.GetConnection();
you can use EF to create the row and get the rowid for the SqliteBlob() call
Did some more research and playing around, and figured out a solution.
For the function, I realized that the BlobTrigger can pass other objects besides a Stream. Specifically a BlockBlobClient, which I used to download the file to the local AppData folder (Azure functions has local storage, but I haven't tested this outside of Azurite yet).
In the DbContext, I added an override to OnConfiguring to allow Sqlite access. Then I was able to pass in the local Sqlite file path and access everything without issue.
Here are the updated cs files I was using for reference:
@Tyler Mason I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others", I'll repost your solution in case you'd like to "Accept" the answer.
Issue:
You observed that you cannot find a way to connect the Function's
[BlobTrigger(~)] Stream stream
argument to the EFDbContext
. When you search for this, the most common thing to come up is the Blob I/O for making an SqliteBlob stream, but that takes a connection string, which isn't given from the Function arguments, and doesn't have an option to create the object using another Stream object. Also even if I'm able to make an SqliteBlob object, I'm still not sure on how that would connect to the DbContext.
Solution:
You did some more research and found that for the function, you can pass other objects for BlobTrigger other besides a Stream. Specifically a BlockBlobClient, which you used to download the file to the local AppData folder
In the DbContext, you added an override to OnConfiguring to allow Sqlite access. Then you was able to pass in the local Sqlite file path and access everything without issue.
Thank you again for your time and patience throughout this issue.