我有一个WebAPI控制器,它接受二进制包并将它们存储在某个地方.由于这些包可能变得非常大,我不想通过添加字节数组参数将它们加载到内存中,而是传递给流.
我在这个答案中找到了一种方法:
[HttpPost]
[Route("Store/{projectId}")]
public async Task Store(string projectId)
{
using (var stream = await this.Request.Content.ReadAsStreamAsync())
{
await this.packageManager.StorePackageAsync(projectId, stream);
}
}
Run Code Online (Sandbox Code Playgroud)
这有效,我可以使用Postman将文件发送到控制器.但是,我现在想用Swashbuckle生成一个swagger文档,当然,那里没有提到所需的正文内容.
有没有办法获得请求内容的流,以便Swashbuckle知道它?或者是否有一个属性我可以用来告诉它所需的内容?
EF Core 2.1引入了对环境事务的支持.该示例创建一个新的SqlConnection,手动打开它并将其传递给DbContext:
using (var scope = new TransactionScope(
TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
{
var connection = new SqlConnection(connectionString);
connection.Open();
try
{
// Run raw ADO.NET command in the transaction
var command = connection.CreateCommand();
command.CommandText = "DELETE FROM dbo.Blogs";
command.ExecuteNonQuery();
// Run an EF Core command in the transaction
var options = new DbContextOptionsBuilder<BloggingContext>()
.UseSqlServer(connection)
.Options;
using (var context = new BloggingContext(options))
{
context.Blogs.Add(new Blog { Url = "http://blogs.msdn.com/dotnet" }); …Run Code Online (Sandbox Code Playgroud)