【发布时间】:2018-06-11 21:27:28
【问题描述】:
我正在使用数据库来存储位置点的集合,并且我正在尝试创建一个消除重复项的列表。到目前为止,它部分工作。目前,当我通过
检查我的列表计数时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; }
}
【问题讨论】:
-
你认为
SELECT DISTINCT driftID是做什么的?你认为它返回name吗?或者只是driftID? -
我以为它会返回名字
-
好的,对,这就是我的问题。我正在存储 GameManager.driftTables 中存储的每个不同漂移的名称,并将其设置为 null,而我想要做的是将 GameManager.driftTables 中每个列表项的名称设置为与从中找到的相同的不同名称查询“SELECT DISTINCTdriftID FROM Drift”
-
您需要将
driftID更改为您的姓名列的名称。 -
"到从查询
SELECT DISTINCT driftID FROM Drift中找到的相同的不同名称。这与从{ red, green, blue }中选择dog有点相同。