Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Sqlite.net overriding column name when it is indexed

$
0
0

I am getting a response from a json api and deseralizing this into a corresponding object as below and saving the results into sqlite db.

        [Table("Product")]
        public class Fields
        {
            [PrimaryKey]
            public int id { get; set; }
            public string status { get; set; }

            [Indexed]
            [Column("CategoryId")]
             public int category { get; set; }       
     }

in the api, it is called as category but I want to save as CategoryId into my sqlite table.

     var conn = new SQLiteConnection("mydatabase.db3");
                    conn.CreateTable<Api.Fields>();

            conn.InsertAll(response);

If I try to create table no problem, it gets created with CategoryId but when I try to insert results, it will complain with the message below,

SQLite.SQLiteException was unhandled by user code
HResult=-2146233088 Message=Constraint Source=SQLite-net
StackTrace:
at SQLite.PreparedSqlLiteInsertCommand.ExecuteNonQuery(Object[] source)
at SQLite.SQLiteConnection.Insert(Object obj, String extra, Type objType)
at SQLite.SQLiteConnection.Insert(Object obj)

This means during the insert it is expecting to insert as a category rather than categoryId. So there should be mapping between them. Although I say [Column("CategoryId")] during the inserting values, it is being ignored.

How can I set that mapping? I see there are some overloads like getmappings or tablemappings but I cant find any usage or syntax information how to use it?


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>