有一个有趣的问题,目前正在构建一个需要使用托管标识连接到 azure sql 的 Web 应用程序,我正在尝试从 nhibernate 创建到 sql 的连接,但使用访问令牌。现在,我已经为实体框架完成了这项工作,它运行良好,但由于某种原因,我无法让它在 nhibernate 上运行。
我的EF代码如下:
def search(request):
if request.method == 'GET':
product_name = request.GET.get('search')
try:
product = Product.objects.filter(name__icontains=product_name)
context = {"product": product}
except:
product = "What is this"
context = {"product":product}
return render(request, "core/search.html", context)
else:
result = "Sorry there is no product with that name"
return render(request, "core/search.html", {"result":result})
这工作得很好,但是当尝试用 nhibernate 做类似的事情时,事情就不那么好了。
public MyDbContext(IDBAuthTokenService tokenService)
{
var connection = this.Database.GetDbConnection() as SqlConnection;
if (!connection.ConnectionString.Contains("Trusted_Connection"))
{
connection.AccessToken = tokenService.GetToken();
}
}
我是否走在正确的道路上?可以这样做吗?
任何帮助将不胜感激。