考虑两个班级.
public class File
{
[Key]
public string Id { get; set; }
public string Message_Id { get; set; }
internal Message Message { get; set; }
}
public class Message
{
[Key]
public string Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在EF6中,对于N:1..0关系,有一个流畅的API.
modelBuilder.Entity<File>()
.HasOptional(e => e.Message ).WithMany().HasForeignKey(e => e.Message_Id);
Run Code Online (Sandbox Code Playgroud)
在Entiity Framework Core 1中有什么相同的东西?
谢谢
entity-framework entity-framework-core .net-core asp.net-core asp.net-core-1.0
我想在控件中自定义实现[Authorize]属性.
这就是我做的.
ConfigureServices中的StartupClass
services.AddAuthorization(options =>
{
options.AddPolicy("Authorize", policy =>
{
policy.AddRequirements(new MyRequirement());
});
});
Run Code Online (Sandbox Code Playgroud)MyRequirement
public class MyRequirement : AuthorizationHandler<MyRequirement>, IAuthorizationRequirement
{
protected override void Handle(AuthorizationContext context, MyRequirement requirement)
{
//some work
//if shloud be authorized
context.Succeed(requirement);
}
}
Run Code Online (Sandbox Code Playgroud)的TestController
[Authorize("Authorize")]
[Route("api/[controller]")]
public class TestController : Controller
{
...
}
Run Code Online (Sandbox Code Playgroud)我错过了什么?永远不会调用MyRequirement授权程序.谢谢.
asp.net asp.net-mvc asp.net-core-mvc asp.net-core asp.net-core-1.0
有没有办法在没有定义具体容器的情况下触发Azure功能?
我期待,下面的函数将被触发任何容器中的任何文件.文件和容器的名称应该是变量.
*****function.json:
{
"bindings": [
{
"type": "blobTrigger",
"name": "myBlob",
"path": "{container}/{name}",
"connection": "AzureWebJobsStorage",
"direction": "in"
}
],
"disabled": false
}
*****run.csx:
public static void Run(Stream myBlob, string name, string container, TraceWriter log, out string outputSbMsg)
{
log.Info("C# Blob trigger function Processed blob");
log.Info(name);
log.Info(container);
}
Run Code Online (Sandbox Code Playgroud)
但是,什么也没有触发.知道什么是错的吗?
我正在托管WCF作为Widnows服务,但我遇到了处理WCF通道的故障状态的问题.ServiceHost上的故障事件永远不会升起.
托管申请:
protected override void OnStart(string[] args)
{
_serviceHost = new ServiceHost(typeof(WCF_FaultTest.Service1));
_serviceHost.Faulted += _serviceHost_Faulted;
_serviceHost.Open();
}
void _serviceHost_Faulted(object sender, EventArgs e)
{
// never raise up..
}
Run Code Online (Sandbox Code Playgroud)
故障状态我尝试模拟这样:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
public class Service1 : IService1
{
public string GetFault()
{
throw new Exception("Should went to fault..");
}
Run Code Online (Sandbox Code Playgroud)
我正确使用它吗?谢谢.
我试图List< int>使用此代码作为SQL参数:
var listID= new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
using (var sqlConnection = new SqlConnection(_connectionstring))
{
using (var cmd = new SqlCommand())
{
cmd.Connection = sqlConnection;
cmd.CommandText = "delete from MyTable where TableID in ( @tableID)";
string param = String.Join(",", listID.ToArray());
cmd.Parameters.Add("@tableID", param);
sqlConnection.Open();
cmd.ExecuteNonQuery();
}
sqlConnection.Close();
}
Run Code Online (Sandbox Code Playgroud)
问题是,此代码将生成:
exec sp_executesql来自MyTable的N'delete,其中TableID位于(@tableID)',N'@ tableID nvarchar(17)',@ tableID = N'1,2,3,4,5,6,7,8,9'
这将失败,因为:
将nvarchar值'1,2,3,4,5,6,7,8,9'转换为数据类型int时转换失败.
不知道怎么解决这个问题?谢谢.
编辑:我正在使用MS SQL 2012
嗨,我在我的应用程序中的几个地方使用TransactionScope.喜欢:
using (var scope = new TransactionScope())
{
ToDo1();
ToDo2();
scope.Complete();
}
Run Code Online (Sandbox Code Playgroud)
我希望有可能在一个地方禁用我的所有TransactionScopes.
我想像MyTransactionScope类,我可以定义是否要使用它.
你能给我一个如何实现它的提示吗?
谢谢.
有没有办法使用 C# 从 git 存储库检索文件历史记录?一些框架会很好。
我所说的文件历史记录只是指名称和更改日期。
在 WebApi2 项目中,我有自定义 Claim,我想将它作为每个请求的自定义属性发送。
我实现了 TelemetryInitializer 但 HttpContext 中的 User 始终为空。
public class MyTelemetryInitializer : ITelemetryInitializer
{
var requestTelemetry = telemetry as RequestTelemetry;
if (requestTelemetry == null) return;
var user= HttpContext.Current.User;
// values from header are wokring
requestTelemetry.Context.Properties["abc"] = HttpContext.Current.Request.Headers.Get("abc");
}
Run Code Online (Sandbox Code Playgroud)
实现这一目标的正确方法是什么?
c# ×4
.net ×3
asp.net-core ×2
.net-core ×1
asp.net ×1
asp.net-mvc ×1
azure ×1
git ×1
sql ×1
wcf ×1