Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
d753b1a2
Commit
d753b1a2
authored
Aug 25, 2018
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ef sent message demo to SqlServer samples
parent
ffba435d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
167 additions
and
4 deletions
+167
-4
AppDbContext.cs
samples/Sample.Kafka.SqlServer/AppDbContext.cs
+23
-0
ValuesController.cs
...es/Sample.Kafka.SqlServer/Controllers/ValuesController.cs
+37
-1
20180825123925_init.Designer.cs
...afka.SqlServer/Migrations/20180825123925_init.Designer.cs
+38
-0
20180825123925_init.cs
.../Sample.Kafka.SqlServer/Migrations/20180825123925_init.cs
+30
-0
AppDbContextModelSnapshot.cs
...e.Kafka.SqlServer/Migrations/AppDbContextModelSnapshot.cs
+36
-0
Startup.cs
samples/Sample.Kafka.SqlServer/Startup.cs
+3
-3
No files found.
samples/Sample.Kafka.SqlServer/AppDbContext.cs
0 → 100644
View file @
d753b1a2
using
Microsoft.EntityFrameworkCore
;
namespace
Sample.Kafka.SqlServer
{
public
class
Person
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
}
public
class
AppDbContext
:
DbContext
{
public
const
string
ConnectionString
=
"Server=localhost;Integrated Security=SSPI;Database=testcap"
;
public
DbSet
<
Person
>
Persons
{
get
;
set
;
}
protected
override
void
OnConfiguring
(
DbContextOptionsBuilder
optionsBuilder
)
{
optionsBuilder
.
UseSqlServer
(
ConnectionString
);
}
}
}
samples/Sample.Kafka.SqlServer/Controllers/ValuesController.cs
View file @
d753b1a2
...
@@ -27,7 +27,7 @@ namespace Sample.Kafka.SqlServer.Controllers
...
@@ -27,7 +27,7 @@ namespace Sample.Kafka.SqlServer.Controllers
[
Route
(
"~/adonet/transaction"
)]
[
Route
(
"~/adonet/transaction"
)]
public
IActionResult
AdonetWithTransaction
()
public
IActionResult
AdonetWithTransaction
()
{
{
using
(
var
connection
=
new
SqlConnection
(
Startup
.
ConnectionString
))
using
(
var
connection
=
new
SqlConnection
(
AppDbContext
.
ConnectionString
))
{
{
using
(
var
transaction
=
connection
.
BeginTransaction
(
_capBus
,
autoCommit
:
false
))
using
(
var
transaction
=
connection
.
BeginTransaction
(
_capBus
,
autoCommit
:
false
))
{
{
...
@@ -43,6 +43,42 @@ namespace Sample.Kafka.SqlServer.Controllers
...
@@ -43,6 +43,42 @@ namespace Sample.Kafka.SqlServer.Controllers
return
Ok
();
return
Ok
();
}
}
[
Route
(
"~/adonet/autocommit/transaction"
)]
public
IActionResult
AdonetAutoCommitWithTransaction
()
{
using
(
var
connection
=
new
SqlConnection
(
AppDbContext
.
ConnectionString
))
{
using
(
var
transaction
=
connection
.
BeginTransaction
(
_capBus
,
autoCommit
:
true
))
{
//your business code
connection
.
Execute
(
"insert into dbo.test1(tname) values('test');"
,
transaction
:
transaction
);
_capBus
.
Publish
(
"sample.kafka.sqlserver"
,
DateTime
.
Now
);
}
}
return
Ok
();
}
[
Route
(
"~/ef/transaction"
)]
public
IActionResult
EntityFrameworkWithTransaction
([
FromServices
]
AppDbContext
dbContext
)
{
using
(
var
trans
=
dbContext
.
Database
.
BeginTransaction
(
_capBus
,
autoCommit
:
false
))
{
dbContext
.
Persons
.
Add
(
new
Person
()
{
Name
=
"ef.transaction"
});
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
_capBus
.
Publish
(
"sample.kafka.sqlserver"
,
DateTime
.
Now
);
}
dbContext
.
SaveChanges
();
trans
.
Commit
();
}
return
Ok
();
}
[
NonAction
]
[
NonAction
]
[
CapSubscribe
(
"sample.kafka.sqlserver"
)]
[
CapSubscribe
(
"sample.kafka.sqlserver"
)]
public
void
Subscriber
(
DateTime
time
)
public
void
Subscriber
(
DateTime
time
)
...
...
samples/Sample.Kafka.SqlServer/Migrations/20180825123925_init.Designer.cs
0 → 100644
View file @
d753b1a2
// <auto-generated />
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Metadata
;
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
using
Sample.Kafka.SqlServer
;
namespace
Sample.Kafka.SqlServer.Migrations
{
[
DbContext
(
typeof
(
AppDbContext
))]
[
Migration
(
"20180825123925_init"
)]
partial
class
init
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"2.1.1-rtm-30846"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
128
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
modelBuilder
.
Entity
(
"Sample.Kafka.SqlServer.Person"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
b
.
Property
<
string
>(
"Name"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Persons"
);
});
#pragma warning restore 612, 618
}
}
}
samples/Sample.Kafka.SqlServer/Migrations/20180825123925_init.cs
0 → 100644
View file @
d753b1a2
using
Microsoft.EntityFrameworkCore.Metadata
;
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
Sample.Kafka.SqlServer.Migrations
{
public
partial
class
init
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
CreateTable
(
name
:
"Persons"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
int
>(
nullable
:
false
)
.
Annotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
),
Name
=
table
.
Column
<
string
>(
nullable
:
true
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_Persons"
,
x
=>
x
.
Id
);
});
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropTable
(
name
:
"Persons"
);
}
}
}
samples/Sample.Kafka.SqlServer/Migrations/AppDbContextModelSnapshot.cs
0 → 100644
View file @
d753b1a2
// <auto-generated />
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Metadata
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
using
Sample.Kafka.SqlServer
;
namespace
Sample.Kafka.SqlServer.Migrations
{
[
DbContext
(
typeof
(
AppDbContext
))]
partial
class
AppDbContextModelSnapshot
:
ModelSnapshot
{
protected
override
void
BuildModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"2.1.1-rtm-30846"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
128
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
modelBuilder
.
Entity
(
"Sample.Kafka.SqlServer.Person"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
b
.
Property
<
string
>(
"Name"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Persons"
);
});
#pragma warning restore 612, 618
}
}
}
samples/Sample.Kafka.SqlServer/Startup.cs
View file @
d753b1a2
...
@@ -5,13 +5,13 @@ namespace Sample.Kafka.SqlServer
...
@@ -5,13 +5,13 @@ namespace Sample.Kafka.SqlServer
{
{
public
class
Startup
public
class
Startup
{
{
public
const
string
ConnectionString
=
"Server=localhost;Integrated Security=SSPI;Database=testcap"
;
public
void
ConfigureServices
(
IServiceCollection
services
)
public
void
ConfigureServices
(
IServiceCollection
services
)
{
{
services
.
AddDbContext
<
AppDbContext
>();
services
.
AddCap
(
x
=>
services
.
AddCap
(
x
=>
{
{
x
.
Use
SqlServer
(
ConnectionString
);
x
.
Use
EntityFramework
<
AppDbContext
>(
);
x
.
UseKafka
(
"localhost:9092"
);
x
.
UseKafka
(
"localhost:9092"
);
x
.
UseDashboard
();
x
.
UseDashboard
();
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment