简体   繁体   中英

Mapping sqlite tables and c# classes for query, insert and update

Is there any way to map a class to a sqlite table?

For instance, if I have a Person class like:

public class Person
{
    public string Name {get; set;}
    public string Surname {get; set;}
    public string BirthDate {get; set;}
}

Is there any way to automatically insert any object into a table that shares the same name as the class and the same columns as its attributes? I thought it would be possible going by this question here , but I can't find the exact package that was being used in that case nor if it really does what I would want.

You could use an object-relational mapper (ORM) such as Entity Framework . Please refer to the "Get Started" links on the following MSDN page for more information: https://docs.microsoft.com/en-us/ef/core/providers/sqlite/

Getting Started with EF Core on Universal Windows Platform (UWP) with a New Database: https://docs.microsoft.com/en-us/ef/core/get-started/uwp/getting-started

SQLite EntityFramework 6 Tutorial: https://erazerbrecht.wordpress.com/2015/06/11/sqlite-entityframework-6-tutorial/

As already said, you need an ORM. I suggest Dapper, very fast and distributed by those running the site we're on. Also, take a look at Automapper which may help you in the process of transforming your data objects in domain objects and back.

Dapper on GitHub

https://github.com/StackExchange/Dapper

Automapper on GitHub

https://github.com/AutoMapper/AutoMapper

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