简体   繁体   中英

praeclarum sqlite-net Table().Where(Expression) gives Member access failed to compile expression exception C#

I am using praeclarum sqlite-net library for xamarin c#, when I am using :

var item = sQLiteConnection.Table<MyClass>()
    .Where(e =>  (e.Id == CurrentId) && (e.name == Currentname));

It gives exception: Member access failed to compile expression

CurrentId and Currentname both have a value. The table does exist with its columns.

MyClass is:

public class MyClass 
{
    [Ignore]
    public List<ClassB> Bs{ get; set; }

    public string BsAsJson { get; set; }

    public string Datestamp { get; set; }

    [PrimaryKey]
    public string ClassId { get; set; }

    public string SomeId { get; set; }

    public string name { get; set; }

    public MyClass ()
    { }

    public MyClass (string datestamp, string id)
    {
        Bs= new List<ClassB>();

        Datestamp = datestamp;

        ClassId = id;

        name= "Bagera";

        SomeId= "SomeValue";
    }
}

Passing CurrentId as parameter fixed my problem.

Before, I used the function like this where Current Id = StaticClassA.MyStaticList[StaticIndex].Id

public list<MyClass> GettAll()
{
  var item = sQLiteConnection.Table<MyClass>()
      .Where(e =>  (e.Id ==  CurrentId) && (e.name == Currentname));

  return item.ToList();
}

The code before will throw => exception: Member access failed to compile expression.

But, when I pass CurrentId as parameter it works fine:

public list<MyClass> GettAll(string id)
{
  var item = sQLiteConnection.Table<MyClass>()
      .Where(e =>  (e.Id == id) && (e.name == Currentname));

  return item.ToList();
}

I still don't know what is the difference !

Hope this will help someone.

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