質問編集履歴
2
DBアクセスコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,6 +46,8 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
+
string test = null;
|
50
|
+
|
49
51
|
using (SQLiteConnection dbConnection = new SQLiteConnection(dbConnectionString.ToString()))
|
50
52
|
|
51
53
|
{
|
@@ -59,6 +61,22 @@
|
|
59
61
|
dbContext.ObjectTrackingEnabled = false;
|
60
62
|
|
61
63
|
/* ここでLINQでSQLを構築しデータアクセス */
|
64
|
+
|
65
|
+
var items = from test in dbContext.GetTable<TestTable>()
|
66
|
+
|
67
|
+
where test.Id == 1
|
68
|
+
|
69
|
+
select test;
|
70
|
+
|
71
|
+
foreach (var item in items)
|
72
|
+
|
73
|
+
{
|
74
|
+
|
75
|
+
test = String.Copy(item.TestName);
|
76
|
+
|
77
|
+
break;
|
78
|
+
|
79
|
+
}
|
62
80
|
|
63
81
|
}
|
64
82
|
|
@@ -74,4 +92,44 @@
|
|
74
92
|
|
75
93
|
}
|
76
94
|
|
95
|
+
|
96
|
+
|
97
|
+
[Table(Name = "T_TEST")]
|
98
|
+
|
99
|
+
public class TestTable
|
100
|
+
|
101
|
+
{
|
102
|
+
|
103
|
+
[Column(Name = "ID", DbType = "BIGINT", CanBeNull = false, IsPrimaryKey = true)]
|
104
|
+
|
105
|
+
public Int64 Id { get; set; }
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
[Column(Name = "TestName", DbType = "NVARCHAR", CanBeNull = false)]
|
110
|
+
|
111
|
+
public string TestName { get; set; }
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
public TestTable()
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
this.Id = -1;
|
120
|
+
|
121
|
+
this.TestName = "";
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
77
131
|
```
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
環境:VisualStudio 2013 .Net Framework 4.5
|
1
DBアクセス部分のコードを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,7 +44,25 @@
|
|
44
44
|
|
45
45
|
};
|
46
46
|
|
47
|
+
|
48
|
+
|
49
|
+
using (SQLiteConnection dbConnection = new SQLiteConnection(dbConnectionString.ToString()))
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
dbConnection.Open();
|
54
|
+
|
55
|
+
using (DataContext dbContext = new DataContext(dbConnection))
|
56
|
+
|
57
|
+
{
|
58
|
+
|
59
|
+
dbContext.ObjectTrackingEnabled = false;
|
60
|
+
|
47
|
-
/* ここでデータ
|
61
|
+
/* ここでLINQでSQLを構築しデータアクセス */
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
}
|
48
66
|
|
49
67
|
dbConnectionString = null;
|
50
68
|
|