我使用数据库来存储位置点的集合,并且我试图创建一个清除重复的列表。它到目前为止部分工作。目前,当我通过
检查我的清单计数时Debug.Log("There are " + GameManager.driftTables.Count() + " drift sets in the list.");
我得到了正确的倒数。但是当我尝试通过
返回每一行的名称时foreach (AllDrifts drift in GameManager.driftTables)
{
Debug.Log(drift.name);
}
我每个人都得到Null。我在这里做错了什么?
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; }
}
答案 0 :(得分:0)
我通过不再使用DISTINCT解决了这个问题,而只是第一次在列表中显示DriftIndex值并在此之后丢弃所有重复项。
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);
}
}
}