T
T
TohaPerdoha82019-01-06 18:23:40
.NET
TohaPerdoha8, 2019-01-06 18:23:40

Help with Dapper and SQLite C#. How to get data and write?

Hello. Help. I have the code below, for some reason it writes values ​​from the database only to the LastName properties. For some reason, FirstName has null. What's the matter?

public static List<PersonModel> LoadPeople()
        {
            using (IDbConnection cnn = new SQLiteConnection(GetConnectionString()))
            {
                var output = cnn.Query<PersonModel>(@"select * from Person", new DynamicParameters());
                return output.ToList();
            }
        }

Here is the PersonModel class:
public class PersonModel
    {
        public int Id { get; set; }
        public string FirtstName { get; set; }
        public string LastName { get; set; }
        public string FullName
        {
            get { return FirtstName + " " + LastName; }
        }
    }

That is, it returns a List in which the elements have LastName values ​​​​from the database, everything is correct. But FirstName is empty.
public static string GetConnectionString(string id = "Default")
        {
            return ConfigurationManager.ConnectionStrings[id].ConnectionString;
        }

<connectionStrings>
    <add name="Default" connectionString="Data Source=.\DemoDB.db;Version=3;" providerName="System.Data.SqlClient" />
  </connectionStrings>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Thror, 2019-04-25
@Thror

Probably because there is a typo in the name of the model property. Fir t stName. It is unlikely that the field is also called in the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question