代码示例:
"Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"
public class MyEntity { public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } }
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions
public DbSet
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext
services.AddSignalR(); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub
app.UseSignalR(routes =>
{
routes.MapHub
CREATE TRIGGER [dbo].[MyEntities_trigger] ON [dbo].[MyEntities] AFTER INSERT,UPDATE,DELETE AS BEGIN EXEC my_stored_procedure; END
CREATE PROCEDURE my_stored_procedure AS BEGIN DECLARE @changesTable TABLE (ChangeType nvarchar(10), MyEntityId int); INSERT INTO @changesTable (ChangeType, MyEntityId) SELECT CASE WHEN ins.Id IS NOT NULL AND del.Id IS NULL THEN 'INSERT' WHEN del.Id IS NOT NULL AND ins.Id IS NULL THEN 'DELETE' ELSE 'UPDATE' END ChangeType, COALESCE(ins.Id, del.Id) MyEntityId FROM inserted ins FULL OUTER JOIN deleted del ON ins.Id = del.Id;
DECLARE @myEntitiesTable TABLE (Id int, Name nvarchar(50), Description n