sqlite in windows runtime component

2019-04-16 19:39发布

am trying to use sqlite in a windows runtime component. But I get some 219 errors when i add the nuget sqlite-net package. couldnt figure it out anywhere. Any similar issues ?

I finally used a store app class library to use sqlite and called those methods in it from my windows runtime component.

method in store app

   public async  Task<IEnumerable<TaskGroup> > GetTaskGroup()
    {
         return await conn.QueryAsync<TaskGroup>("select * from TaskGroup");

    }

calling method in win runtime component

public IAsyncOperation<IEnumerable<TaskGroup>> GetAllTaskGroup()
    {
        return m_objDAL.GetTaskGroup().AsAsyncOperation();

    }

i get the following error

Error   1   Method 'Tasker.BAL.TaskManager.GetAllTaskGroup()' has a parameter of type 'Windows.Foundation.IAsyncOperation<System.Collections.Generic.IEnumerable<SQLLite.Models.TaskGroup>>' in its signature. Although this generic type is not a valid Windows Runtime type, the type or its generic parameters implement interfaces that are valid Windows Runtime types. Consider changing the type 'SQLLite.Models.TaskGroup' in the method signature. It is not a valid Windows Runtime parameter type.   

making the store app method as private resolves it as per this blog http://rarcher.azurewebsites.net/Post/PostContent/23

but i cant ue this since it will give me access issues since it is private.

any soln ?

2条回答
甜甜的少女心
2楼-- · 2019-04-16 20:28

I don't understand what these errors are, but did you first install the SQLite for Windows Runtime through Tools > Extensions? sqlite-net is LINQ query library

查看更多
We Are One
3楼-- · 2019-04-16 20:30

A Windows runtime component has many limitations regarding the types it exposes externally.

When you include sqlite-net, all its types are declared public and would effectively become exposed by the component. This is the reson for the errors you are seeing.

You can do one of two things to resolve the problem:

  • You can change all public modifiers in SQLite.cs and SQLiteAsync.cs files to internal. This will make it more difficult for you to update the package to a newer version since you'll have to repeat the process every time (a couple of minutes of work).
  • You can create a separate Windows Store apps class library, reference sqlite-net from there and reference this class library from your Windows runtime component. This way sqlite-net's classes won't be automatically exposed by the component.
查看更多
登录 后发表回答