SQLite + Linq => Crap

  • C#

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von slice.

    SQLite + Linq => Crap

    Ich habe irwie immer nur komische Probleme :P

    Naja wie dem auch sei.
    Ich habe eine SQLite Datenbank.
    Aufbau is easy:

    per dblinq2007 habe ich nun eine Main.cs gemacht:
    LONG

    C#-Quellcode

    1. //
    2. // ____ _ __ __ _ _
    3. // | _ \| |__ | \/ | ___| |_ __ _| |
    4. // | | | | '_ \| |\/| |/ _ \ __/ _` | |
    5. // | |_| | |_) | | | | __/ || (_| | |
    6. // |____/|_.__/|_| |_|\___|\__\__,_|_|
    7. //
    8. // Auto-generated from main on 2012-07-05 16:44:51Z.
    9. // Please visit http://code.google.com/p/dblinq2007/ for more information.
    10. //
    11. namespace Social_Network.NET_Server.Databases
    12. {
    13. using System;
    14. using System.ComponentModel;
    15. using System.Data;
    16. #if MONO_STRICT
    17. using System.Data.Linq;
    18. #else // MONO_STRICT
    19. using DbLinq.Data.Linq;
    20. using DbLinq.Vendor;
    21. #endif // MONO_STRICT
    22. using System.Data.Linq.Mapping;
    23. using System.Diagnostics;
    24. public partial class Main : DataContext
    25. {
    26. #region Extensibility Method Declarations
    27. partial void OnCreated();
    28. #endregion
    29. public Main(string connectionString) :
    30. base(connectionString)
    31. {
    32. this.OnCreated();
    33. }
    34. public Main(string connection, MappingSource mappingSource) :
    35. base(connection, mappingSource)
    36. {
    37. this.OnCreated();
    38. }
    39. public Main(IDbConnection connection, MappingSource mappingSource) :
    40. base(connection, mappingSource)
    41. {
    42. this.OnCreated();
    43. }
    44. public Table<Settings> Settings
    45. {
    46. get
    47. {
    48. return this.GetTable<Settings>();
    49. }
    50. }
    51. public Table<Users> Users
    52. {
    53. get
    54. {
    55. return this.GetTable<Users>();
    56. }
    57. }
    58. }
    59. #region Start MONO_STRICT
    60. #if MONO_STRICT
    61. public partial class Main
    62. {
    63. public Main(IDbConnection connection) :
    64. base(connection)
    65. {
    66. this.OnCreated();
    67. }
    68. }
    69. #region End MONO_STRICT
    70. #endregion
    71. #else // MONO_STRICT
    72. public partial class Main
    73. {
    74. public Main(IDbConnection connection) :
    75. base(connection, new DbLinq.Sqlite.SqliteVendor())
    76. {
    77. this.OnCreated();
    78. }
    79. public Main(IDbConnection connection, IVendor sqlDialect) :
    80. base(connection, sqlDialect)
    81. {
    82. this.OnCreated();
    83. }
    84. public Main(IDbConnection connection, MappingSource mappingSource, IVendor sqlDialect) :
    85. base(connection, mappingSource, sqlDialect)
    86. {
    87. this.OnCreated();
    88. }
    89. }
    90. #region End Not MONO_STRICT
    91. #endregion
    92. #endif // MONO_STRICT
    93. #endregion
    94. [Table(Name="main.settings")]
    95. public partial class Settings
    96. {
    97. private sbyte _canReadAbout;
    98. private sbyte _canReadBirthDate;
    99. private sbyte _canReadID;
    100. private sbyte _canReadMail;
    101. private sbyte _canReadRegDate;
    102. private sbyte _inSearch;
    103. private sbyte _showOnline;
    104. private string _uid;
    105. #region Extensibility Method Declarations
    106. partial void OnCreated();
    107. partial void OnCanReadAboutChanged();
    108. partial void OnCanReadAboutChanging(sbyte value);
    109. partial void OnCanReadBirthDateChanged();
    110. partial void OnCanReadBirthDateChanging(sbyte value);
    111. partial void OnCanReadIDChanged();
    112. partial void OnCanReadIDChanging(sbyte value);
    113. partial void OnCanReadMailChanged();
    114. partial void OnCanReadMailChanging(sbyte value);
    115. partial void OnCanReadRegDateChanged();
    116. partial void OnCanReadRegDateChanging(sbyte value);
    117. partial void OnInSearchChanged();
    118. partial void OnInSearchChanging(sbyte value);
    119. partial void OnShowOnlineChanged();
    120. partial void OnShowOnlineChanging(sbyte value);
    121. partial void OnUIDChanged();
    122. partial void OnUIDChanging(string value);
    123. #endregion
    124. public Settings()
    125. {
    126. this.OnCreated();
    127. }
    128. [Column(Storage="_canReadAbout", Name="canReadAbout", DbType="tinyint", AutoSync=AutoSync.Never, CanBeNull=false)]
    129. [DebuggerNonUserCode()]
    130. public sbyte CanReadAbout
    131. {
    132. get
    133. {
    134. return this._canReadAbout;
    135. }
    136. set
    137. {
    138. if ((_canReadAbout != value))
    139. {
    140. this.OnCanReadAboutChanging(value);
    141. this._canReadAbout = value;
    142. this.OnCanReadAboutChanged();
    143. }
    144. }
    145. }
    146. [Column(Storage="_canReadBirthDate", Name="canReadBirthDate", DbType="tinyint", AutoSync=AutoSync.Never, CanBeNull=false)]
    147. [DebuggerNonUserCode()]
    148. public sbyte CanReadBirthDate
    149. {
    150. get
    151. {
    152. return this._canReadBirthDate;
    153. }
    154. set
    155. {
    156. if ((_canReadBirthDate != value))
    157. {
    158. this.OnCanReadBirthDateChanging(value);
    159. this._canReadBirthDate = value;
    160. this.OnCanReadBirthDateChanged();
    161. }
    162. }
    163. }
    164. [Column(Storage="_canReadID", Name="canReadId", DbType="tinyint", AutoSync=AutoSync.Never, CanBeNull=false)]
    165. [DebuggerNonUserCode()]
    166. public sbyte CanReadID
    167. {
    168. get
    169. {
    170. return this._canReadID;
    171. }
    172. set
    173. {
    174. if ((_canReadID != value))
    175. {
    176. this.OnCanReadIDChanging(value);
    177. this._canReadID = value;
    178. this.OnCanReadIDChanged();
    179. }
    180. }
    181. }
    182. [Column(Storage="_canReadMail", Name="canReadMail", DbType="tinyint", AutoSync=AutoSync.Never, CanBeNull=false)]
    183. [DebuggerNonUserCode()]
    184. public sbyte CanReadMail
    185. {
    186. get
    187. {
    188. return this._canReadMail;
    189. }
    190. set
    191. {
    192. if ((_canReadMail != value))
    193. {
    194. this.OnCanReadMailChanging(value);
    195. this._canReadMail = value;
    196. this.OnCanReadMailChanged();
    197. }
    198. }
    199. }
    200. [Column(Storage="_canReadRegDate", Name="canReadRegDate", DbType="tinyint", AutoSync=AutoSync.Never, CanBeNull=false)]
    201. [DebuggerNonUserCode()]
    202. public sbyte CanReadRegDate
    203. {
    204. get
    205. {
    206. return this._canReadRegDate;
    207. }
    208. set
    209. {
    210. if ((_canReadRegDate != value))
    211. {
    212. this.OnCanReadRegDateChanging(value);
    213. this._canReadRegDate = value;
    214. this.OnCanReadRegDateChanged();
    215. }
    216. }
    217. }
    218. [Column(Storage="_inSearch", Name="inSearch", DbType="tinyint", AutoSync=AutoSync.Never, CanBeNull=false)]
    219. [DebuggerNonUserCode()]
    220. public sbyte InSearch
    221. {
    222. get
    223. {
    224. return this._inSearch;
    225. }
    226. set
    227. {
    228. if ((_inSearch != value))
    229. {
    230. this.OnInSearchChanging(value);
    231. this._inSearch = value;
    232. this.OnInSearchChanged();
    233. }
    234. }
    235. }
    236. [Column(Storage="_showOnline", Name="showOnline", DbType="tinyint", AutoSync=AutoSync.Never, CanBeNull=false)]
    237. [DebuggerNonUserCode()]
    238. public sbyte ShowOnline
    239. {
    240. get
    241. {
    242. return this._showOnline;
    243. }
    244. set
    245. {
    246. if ((_showOnline != value))
    247. {
    248. this.OnShowOnlineChanging(value);
    249. this._showOnline = value;
    250. this.OnShowOnlineChanged();
    251. }
    252. }
    253. }
    254. [Column(Storage="_uid", Name="uid", DbType="text", AutoSync=AutoSync.Never, CanBeNull=false)]
    255. [DebuggerNonUserCode()]
    256. public string UID
    257. {
    258. get
    259. {
    260. return this._uid;
    261. }
    262. set
    263. {
    264. if (((_uid == value)
    265. == false))
    266. {
    267. this.OnUIDChanging(value);
    268. this._uid = value;
    269. this.OnUIDChanged();
    270. }
    271. }
    272. }
    273. }
    274. [Table(Name="main.users")]
    275. public partial class Users
    276. {
    277. private string _about;
    278. private System.DateTime _birth;
    279. private string _follows;
    280. private string _mail;
    281. private string _nick;
    282. private string _password;
    283. private System.DateTime _reGdAte;
    284. private string _uid;
    285. #region Extensibility Method Declarations
    286. partial void OnCreated();
    287. partial void OnAboutChanged();
    288. partial void OnAboutChanging(string value);
    289. partial void OnBirthChanged();
    290. partial void OnBirthChanging(System.DateTime value);
    291. partial void OnFollowsChanged();
    292. partial void OnFollowsChanging(string value);
    293. partial void OnMailChanged();
    294. partial void OnMailChanging(string value);
    295. partial void OnNickChanged();
    296. partial void OnNickChanging(string value);
    297. partial void OnPasswordChanged();
    298. partial void OnPasswordChanging(string value);
    299. partial void OnReGDateChanged();
    300. partial void OnReGDateChanging(System.DateTime value);
    301. partial void OnUIDChanged();
    302. partial void OnUIDChanging(string value);
    303. #endregion
    304. public Users()
    305. {
    306. this.OnCreated();
    307. }
    308. [Column(Storage="_about", Name="about", DbType="text", AutoSync=AutoSync.Never)]
    309. [DebuggerNonUserCode()]
    310. public string About
    311. {
    312. get
    313. {
    314. return this._about;
    315. }
    316. set
    317. {
    318. if (((_about == value)
    319. == false))
    320. {
    321. this.OnAboutChanging(value);
    322. this._about = value;
    323. this.OnAboutChanged();
    324. }
    325. }
    326. }
    327. [Column(Storage="_birth", Name="birth", DbType="datetime", AutoSync=AutoSync.Never, CanBeNull=false)]
    328. [DebuggerNonUserCode()]
    329. public System.DateTime Birth
    330. {
    331. get
    332. {
    333. return this._birth;
    334. }
    335. set
    336. {
    337. if ((_birth != value))
    338. {
    339. this.OnBirthChanging(value);
    340. this._birth = value;
    341. this.OnBirthChanged();
    342. }
    343. }
    344. }
    345. [Column(Storage="_follows", Name="follows", DbType="text", AutoSync=AutoSync.Never)]
    346. [DebuggerNonUserCode()]
    347. public string Follows
    348. {
    349. get
    350. {
    351. return this._follows;
    352. }
    353. set
    354. {
    355. if (((_follows == value)
    356. == false))
    357. {
    358. this.OnFollowsChanging(value);
    359. this._follows = value;
    360. this.OnFollowsChanged();
    361. }
    362. }
    363. }
    364. [Column(Storage="_mail", Name="mail", DbType="text", AutoSync=AutoSync.Never, CanBeNull=false)]
    365. [DebuggerNonUserCode()]
    366. public string Mail
    367. {
    368. get
    369. {
    370. return this._mail;
    371. }
    372. set
    373. {
    374. if (((_mail == value)
    375. == false))
    376. {
    377. this.OnMailChanging(value);
    378. this._mail = value;
    379. this.OnMailChanged();
    380. }
    381. }
    382. }
    383. [Column(Storage="_nick", Name="nick", DbType="text", AutoSync=AutoSync.Never, CanBeNull=false)]
    384. [DebuggerNonUserCode()]
    385. public string Nick
    386. {
    387. get
    388. {
    389. return this._nick;
    390. }
    391. set
    392. {
    393. if (((_nick == value)
    394. == false))
    395. {
    396. this.OnNickChanging(value);
    397. this._nick = value;
    398. this.OnNickChanged();
    399. }
    400. }
    401. }
    402. [Column(Storage="_password", Name="password", DbType="text", AutoSync=AutoSync.Never, CanBeNull=false)]
    403. [DebuggerNonUserCode()]
    404. public string Password
    405. {
    406. get
    407. {
    408. return this._password;
    409. }
    410. set
    411. {
    412. if (((_password == value)
    413. == false))
    414. {
    415. this.OnPasswordChanging(value);
    416. this._password = value;
    417. this.OnPasswordChanged();
    418. }
    419. }
    420. }
    421. [Column(Storage="_reGdAte", Name="regdate", DbType="datetime", AutoSync=AutoSync.Never, CanBeNull=false)]
    422. [DebuggerNonUserCode()]
    423. public System.DateTime ReGDate
    424. {
    425. get
    426. {
    427. return this._reGdAte;
    428. }
    429. set
    430. {
    431. if ((_reGdAte != value))
    432. {
    433. this.OnReGDateChanging(value);
    434. this._reGdAte = value;
    435. this.OnReGDateChanged();
    436. }
    437. }
    438. }
    439. [Column(Storage="_uid", Name="uid", DbType="text", AutoSync=AutoSync.Never, CanBeNull=false)]
    440. [DebuggerNonUserCode()]
    441. public string UID
    442. {
    443. get
    444. {
    445. return this._uid;
    446. }
    447. set
    448. {
    449. if (((_uid == value)
    450. == false))
    451. {
    452. this.OnUIDChanging(value);
    453. this._uid = value;
    454. this.OnUIDChanged();
    455. }
    456. }
    457. }
    458. }
    459. }

    Der Aufruf dabei:

    Quellcode

    1. D:\Git\SocialNetwork.NET\source\Social Network.NET Server\Databases>D:\Dateien\DLLs\dblinq\DbMetal.exe /provider:SQLite Source=Main.db" /code:Main.cs --namespace=Social_Network.NET_Server.Databases

    Wenn ich nun diesen Code ausführe:

    C#-Quellcode

    1. Databases.Users whatthefuck = new Databases.Users(){UID = id, Mail = splited[3], Nick = splited[2], Birth = d.Date, Password = splited[4], ReGDate = DateTime.Now, About = "", Follows = "" };
    2. instance.data.Users.InsertOnSubmit(whatthefuck);
    3. instance.data.SubmitChanges();

    instance is ne Instanz von Server.
    data is ne Instanz von Main.

    bekomme ich bei SubmitChanges() folgenden Fehler:

    Quellcode

    1. ArgumentNullException
    2. Der Wert darf nicht NULL sein.
    3. Parametername: key


    StackTrace:

    Quellcode

    1. bei System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
    2. bei System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
    3. bei DbLinq.Data.Linq.Implementation.EntityTracker.FindByIdentity(IdentityKey identityKey) in z:\Development\DbLinq-0.20.1\src\DbLinq\Data\Linq\Implementation\EntityTracker.cs:Zeile 69.
    4. bei DbLinq.Data.Linq.Implementation.EntityTracker.RegisterToWatch(Object entity, IdentityKey identityKey) in z:\Development\DbLinq-0.20.1\src\DbLinq\Data\Linq\Implementation\EntityTracker.cs:Zeile 128.
    5. bei DbLinq.Data.Linq.DataContext.MoveToAllTrackedEntities(Object entity, Boolean insert) in z:\Development\DbLinq-0.20.1\src\DbLinq\Data\Linq\DataContext.cs:Zeile 576.
    6. bei DbLinq.Data.Linq.DataContext.InsertEntity(Object entity, QueryContext queryContext) in z:\Development\DbLinq-0.20.1\src\DbLinq\Data\Linq\DataContext.cs:Zeile 511.
    7. bei DbLinq.Data.Linq.DataContext.SubmitChangesImpl(ConflictMode failureMode) in z:\Development\DbLinq-0.20.1\src\DbLinq\Data\Linq\DataContext.cs:Zeile 451.
    8. bei DbLinq.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) in z:\Development\DbLinq-0.20.1\src\DbLinq\Data\Linq\DataContext.cs:Zeile 406.
    9. bei DbLinq.Data.Linq.DataContext.SubmitChanges() in z:\Development\DbLinq-0.20.1\src\DbLinq\Data\Linq\DataContext.cs:Zeile 368.
    10. bei Social_Network.NET_Server.server.Connection.runCommand(String line) in D:\Git\SocialNetwork.NET\source\Social Network.NET Server\server.cs:Zeile 322.
    11. bei System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
    12. bei System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

    Jemand ne Idee, wie ichs beheben kann?
    öhm ja ^^ gute frage ich nutz dblinq nicht (hab davon gerade das erstema gehört)
    vll ists auch n parameter bei "SubmitChanges"? dafür müsste man ma schaun wo dort der wert genutzt wird etc...
    ich schaus mir ma eben an un meld mich denne wenn i was gefunden hab :)


    €dit: welche der dlls nutzt du?

    €dit: fail, kurze zwischen frage xD hast du in deiner db ein attribut als "primary key" geflaggt?
    wenn nich dann ignorier alles was ich gesagt hab un flagge ein attribut als primkey
    code.google.com/p/dblinq2007/issues/detail?id=225 :D

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „slice“ ()