Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
TourDataManager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
Kirill
TourDataManager
Commits
f0633a9f
Commit
f0633a9f
authored
Oct 15, 2018
by
Kirill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавление Files в базу данных без коллизий. Создание базы данных в persistent директории
parent
13c40374
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
Db.cs
TourDataManager/Db.cs
+5
-5
No files found.
TourDataManager/Db.cs
View file @
f0633a9f
...
@@ -44,8 +44,9 @@ namespace TourDataManager {
...
@@ -44,8 +44,9 @@ namespace TourDataManager {
.
HasDatabaseGeneratedOption
(
DatabaseGeneratedOption
.
None
);
.
HasDatabaseGeneratedOption
(
DatabaseGeneratedOption
.
None
);
// Ещё, вероятно, помогло бы [DatabaseGenerated(DatabaseGeneratedOption.None)]
// Ещё, вероятно, помогло бы [DatabaseGenerated(DatabaseGeneratedOption.None)]
var
sqliteConnectionInitializer
=
new
Sqlite
DropCreateDatabaseWhenModelChange
s
<
MyDbContext
>(
modelBuilder
);
var
sqliteConnectionInitializer
=
new
Sqlite
CreateDatabaseIfNotExist
s
<
MyDbContext
>(
modelBuilder
);
Database
.
SetInitializer
(
sqliteConnectionInitializer
);
Database
.
SetInitializer
(
sqliteConnectionInitializer
);
}
}
public
DbSet
<
Estate
>
Estates
{
get
;
set
;
}
public
DbSet
<
Estate
>
Estates
{
get
;
set
;
}
...
@@ -62,7 +63,7 @@ namespace TourDataManager {
...
@@ -62,7 +63,7 @@ namespace TourDataManager {
private
MyDbContext
context
;
private
MyDbContext
context
;
public
Db
(){
public
Db
(){
connection
=
new
SQLiteConnection
(
"data source=mylovelybase.sqlite
"
);
connection
=
new
SQLiteConnection
(
$"data source=
{
TourDataManager
.
GetPathInPersistent
(
"sandbox.sqlite"
)}
"
);
context
=
new
MyDbContext
(
connection
,
true
);
context
=
new
MyDbContext
(
connection
,
true
);
}
}
...
@@ -89,9 +90,8 @@ namespace TourDataManager {
...
@@ -89,9 +90,8 @@ namespace TourDataManager {
}
}
public
void
InsertFiles
(
IEnumerable
<
File
>
files
){
public
void
InsertFiles
(
IEnumerable
<
File
>
files
){
foreach
(
var
file
in
files
){
var
diff
=
files
.
Where
(
file
=>
!
context
.
Files
.
Any
(
file1
=>
file
.
Url
==
file1
.
Url
));
context
.
Files
.
AddOrUpdate
(
file
);
context
.
Files
.
AddRange
(
diff
);
}
context
.
SaveChanges
();
context
.
SaveChanges
();
}
}
...
...
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