0

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.

mjgalindo
  • 856
  • 11
  • 26
  • 1
    The term you're looking for is called "Object Relational Mapper" or ORM. There are plenty of different ones available, which you can find with a little bit of research. – mason Sep 08 '17 at 15:18

2 Answers2

2

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://learn.microsoft.com/en-us/ef/core/providers/sqlite/

Getting Started with EF Core on Universal Windows Platform (UWP) with a New Database: https://learn.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/

mm8
  • 163,881
  • 10
  • 57
  • 88
1

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

Community
  • 1
  • 1
ccalboni
  • 12,120
  • 5
  • 30
  • 38