35

I have one entity class as

  public class someclass
  {
      public string property1 {get; set;}
      public string property2 {get; set;}
      public string property3 {get; set;}
  }

and using sqlite connection class obj DB I am creating the table

  Db.CreateTableAsync<someclass>().GetAwaiter().GetResult();

What I want to achieve is, I don't want sqlite to create column in the table for property3. Is there any way to achieve this?

I am using SQLiteAsync library for windows store apps.

1
  • I think you can't because there's no method to create table using column names. Right now we have just a method which passes the class name(s) as argument. Commented May 6, 2013 at 12:20

3 Answers 3

89

You can use the Ignore attribute:

public class someclass
{
    public string property1 { get; set; }
    public string property2 { get; set; }
    [Ignore]
    public string property3 { get; set; }
}
2
12

As chue x has said previously, you should use the Ignore attribute, but I figured I would give a bit more information as to what all the attributes do since it seems like some information that would be useful in this thread.

Here's a quick summary of the types of attributes available for use (for those of you that don't like reading and just want to know quickly):

PrimaryKey - This property is the primary key of the table. Only single-column primary keys are supported.

AutoIncrement - This property is automatically generated by the database upon insert.

Indexed - This property should have an index created for it.

MaxLength - If this property is a String then MaxLength is used to specify the varchar max size. The default max length is 140.

Ignore - This property will not be in the table.

If you want to know more, check out my more in depth blog post on these attributes:

http://lukealderton.com/blog/posts/2016/august/sqlite-attributes-and-what-they-do.aspx

1
  • Also PrimaryKey has hidden Indexed inside, meaning all primary keys are indexed by default and you don't need to use both properties.
    – s3c
    Commented Sep 10, 2021 at 8:45
0

You can add ignore attribute as in this code:

        [ObservableProperty][property: PrimaryKey, AutoIncrement, Column("ara_id")] public int ara_id;
    [ObservableProperty][property: Ignore] public StareAratare ara_stare;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.