简体   繁体   中英

C# sqlite entity framework - map string type

In SQLite in table I have column: Title and type of this column is string. Now I want to map this table to Entity Framework in C#. And problem is with type string of that column because I cannot map it to string type in C#. It works when I change in SQLite string to VARCHAR. But how to resolve this problem without changing column type?

Most SQL database engines (every SQL database engine other than SQLite, as far as we know) uses static, rigid typing. With static typing, the datatype of a value is determined by its container - the particular column in which the value is stored.

SQLite uses a more general dynamic type system. In SQLite, the datatype of a value is associated with the value itself, not with its container. The dynamic type system of SQLite is backwards compatible with the more common static type systems of other database engines in the sense that SQL statements that work on statically typed databases should work the same way in SQLite. However, the dynamic typing in SQLite allows it to do things which are not possible in traditional rigidly typed databases. SqlLite Datatypes Reference

According to documentation the System.String is mapped to TEXT in SQLite so you cannot use string datatype for SQLite.

TEXT : The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).

Here is a table that's showing .Net SQLite default type mapping. 在此处输入图片说明 For more information please see Entity Framework Data Types Mapping with .Net

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM