Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create c# class with a table. Sqlite-net

I have SQLite database in isolated storage in Windows Store App. I use SQLite for Windows Runtime

My class:

[Table("Projects")]
public class Project
{
    [PrimaryKey]
    [Column ("id")]
    public int Id { get; set; }

    [Column("group_id")]
    public int GroupId { get; set; }

    public string Name { get; set; }
}

I get data from web server and put it to local DataBase. When I try to store data to DataBase, I handled exeption

 e.message = table Projects has no column named Name 

because DataBase haven't column "Name"

My question is: How to use one class with fields, maping to DataBase Column and simple fields? (I wont not include some fields to DataBase, but I need it in class.)

UPD.

using System.ComponentModel.DataAnnotations.Schema;

[NotMapped]
public string Name { get; set; }

Error The type or namespace name 'NotMappedAttribute' does not exist in the namespace 'System.ComponentModel.DataAnnotations.Schema' (are you missing an assembly reference?)   

When I try to add System.ComponentModel.DataAnnotations.dll Error: System.ComponentModel.DataAnnotations.dll could not be added. This component is already automaticaly referenced by the build system.

like image 587
jimpanzer Avatar asked Apr 21 '26 04:04

jimpanzer


1 Answers

It seems you are using the sqlite-net library in this case you need to use the SQLite.IgnoreAttribute

[SQLite.Ignore]
public string Name { get; set; }
like image 50
nemesv Avatar answered Apr 23 '26 17:04

nemesv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!