Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 列表中的值为空,而不是名称_C#_List_Sqlite_Unity3d - Fatal编程技术网

C# 列表中的值为空,而不是名称

C# 列表中的值为空,而不是名称,c#,list,sqlite,unity3d,C#,List,Sqlite,Unity3d,我正在使用一个数据库来存储位置点的集合,并试图创建一个列表来消除重复项。到目前为止,它仍在部分工作。当前,当我通过 Debug.Log("There are " + GameManager.driftTables.Count() + " drift sets in the list."); 我得到了正确的倒计时。但是当我试图通过返回每一行的名称时 foreach (AllDrifts drift in GameManager.driftTables) {

我正在使用一个数据库来存储位置点的集合,并试图创建一个列表来消除重复项。到目前为止,它仍在部分工作。当前,当我通过

Debug.Log("There are " + GameManager.driftTables.Count() + " drift sets in the list.");
我得到了正确的倒计时。但是当我试图通过返回每一行的名称时

foreach (AllDrifts drift in GameManager.driftTables)
            {
                Debug.Log(drift.name);
            }
每一个都是空的。我在这里做错了什么

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using SimpleSQL;
using System.Runtime.InteropServices.ComTypes;

public class SQLiteActions : MonoBehaviour
{
    int driftCount;

    public void GetDriftTablesList()
    {
        GameManager.driftTables =
            DriftsDatabaseManager.Query<AllDrifts>(
                "SELECT DISTINCT driftID " +
                "FROM Drift"
            );

        foreach (AllDrifts drift in GameManager.driftTables)
        {
            Debug.Log(drift.name);
        }

        Debug.Log("There are " + GameManager.driftTables.Count() + " drift sets in the list.");
    }
}

public class AllDrifts
{
    [PrimaryKey]
    public string name { get; set; }
}

我解决了这个问题,不再使用DISTINCT,而是在列表中第一次出现一个DRIFTDINDEX值时查找,然后丢弃所有重复项,就像这样

using UnityEngine;
using System.Linq;
using SimpleSQL;

    public class DriftSets
    {
        [PrimaryKey, AutoIncrement]
        public int DriftIndex { get; set; }
        public string DriftID { get; set; }
        public string DriftDateTime { get; set; }
        public string DriftName { get; set; }
        public string DriftStep { get; set; }
        public float DriftLat { get; set; }
        public float DriftLong { get; set; }
        public string DriftTexLocation { get; set; }
    }

    public class SQLiteActions : MonoBehaviour
    {
        public static SQLiteActions instance = null;
        // reference to the database manager in the scene
        public SimpleSQLManager DriftsDatabaseManager;

        private string sql;

        public void GetDriftTablesList()
        {
            sql =
                "SELECT MIN(DriftIndex), DriftID, DriftName, DriftDateTime, DriftTexLocation  " +
                "FROM Drift " +
                "GROUP BY DriftID " +
                "ORDER BY DriftDateTime DESC";

            GameManager.driftSets = DriftsDatabaseManager.Query<DriftSets>(sql);

            foreach (var driftSet in GameManager.driftSets)
            {
                Debug.Log(driftSet.DriftName);
            }
        }
     }

你认为我是干什么的?你认为它会返回名称吗?或者只是漂流ID?我想它会返回名字好吧,对,这就是我的问题。我正在存储,并且在GameManager.floftTables中存储的每个不同漂移的名称都将为null,我想做的是将GameManager.floftTables中每个列表项的名称设置为从查询中找到的同一个不同名称选择distinct FloftId from Floft您需要将FloftId更改为名称列的名称。要使用从查询中找到的同一个不同名称,请选择distinct FloftId from Floft。这和从{红、绿、蓝}中选择狗有点一样。