signalR dotnet 核心问题
Issue on signalR dotnet core
问题
场景:
- SignalR 版本 1.0.0 RC1 Final
- 点网核心 2.0
- 典型:用户 - 帖子 - 评论模型。
问题:
当我通过 websocket 发送模型时静默失败(没有消息发送到客户端)。如果我设置为空导航 属性:
它工作正常
_context.Posts.Add(model);
_context.SaveChanges();
model.User.Posts = null; // <- removing this line fails silently
_hub.Clients.All.SendAsync("AddAsync", model);
我如何诊断发生了什么?有人知道是什么原因吗?
一些不必要的代码细节
User.cs
public Guid Id { get; set; }
// ...
public virtual List<Post> Posts { get; set; } = new List<Post>();
Post.cs
public Guid Id { get; set; }
// ...
public virtual User User { get; set; }
PostsController.cs
private IHubContext<PostsHub> _hub;
private DatabaseContext _context;
public PostsController(IHubContext<PostsHub> hub)
{
_hub = hub;
}
// ...
[HttpPost]
public async Task<ActionResult> PostAsync([FromBody] Post model)
{
// ...
_context.Posts.Add(model);
_context.SaveChanges();
model.User.Posts = null;
_hub.Clients.All.SendAsync("AddAsync", model);
// ...
}
使用 json convert 将模型序列化为 json 并在发送之前再次将其反序列化为 Post 对象。
如果有错误,它应该在那里弹出,因为如果有依赖循环 json convert 应该抛出异常
问题
场景:
- SignalR 版本 1.0.0 RC1 Final
- 点网核心 2.0
- 典型:用户 - 帖子 - 评论模型。
问题:
当我通过 websocket 发送模型时静默失败(没有消息发送到客户端)。如果我设置为空导航 属性:
它工作正常 _context.Posts.Add(model);
_context.SaveChanges();
model.User.Posts = null; // <- removing this line fails silently
_hub.Clients.All.SendAsync("AddAsync", model);
我如何诊断发生了什么?有人知道是什么原因吗?
一些不必要的代码细节
User.cs
public Guid Id { get; set; }
// ...
public virtual List<Post> Posts { get; set; } = new List<Post>();
Post.cs
public Guid Id { get; set; }
// ...
public virtual User User { get; set; }
PostsController.cs
private IHubContext<PostsHub> _hub;
private DatabaseContext _context;
public PostsController(IHubContext<PostsHub> hub)
{
_hub = hub;
}
// ...
[HttpPost]
public async Task<ActionResult> PostAsync([FromBody] Post model)
{
// ...
_context.Posts.Add(model);
_context.SaveChanges();
model.User.Posts = null;
_hub.Clients.All.SendAsync("AddAsync", model);
// ...
}
使用 json convert 将模型序列化为 json 并在发送之前再次将其反序列化为 Post 对象。 如果有错误,它应该在那里弹出,因为如果有依赖循环 json convert 应该抛出异常