私はこのような2つのオブジェクトを持っています:
public class Place : ICloneable, IEquatable<Place>
{
public string Name{ get; set; }
public float longitude{ get; set; }
public float latitude{ get; set; }
public Horizon thehorizon { get; set; }
...
}
public class Horizon
{
public List<PointF> points{ get; set; }
}
私のデータベースには、「場所」と「地平線」の2つのテーブルがあり、地平線に外部キーがあり、ポイントがどの場所に属しているかがわかります。
したがって、場所の構造は次のとおりです。
- 名前 -nvarchar - 主キー
- 経度 - 実数
- 緯度 - 実数
そして地平線の構造は
- parent_key - nvarchar
- pointX - 実数
- poinY - リアル
以下のコードを書いて、すべてのデータを選択し、場所のリストを作成しました。動作していますが、非常に遅いです。高速化する方法に関する提案 (またはコメント) があれば、教えてください。
DataTable TablePlaces;
DataTable TableHorizons;
public void init()
{
TablePlaces = new DataTable();
TablePlaces.Columns.Add("Name");
TablePlaces.Columns.Add("longitude");
TablePlaces.Columns.Add("latitude");
TableHorizons = new DataTable();
TableHorizons.Columns.Add("parent_key");
TableHorizons.Columns.Add("pointX");
TableHorizons.Columns.Add("pointY");
System.Data.DataSet DS = new DataSet();
DS.Tables.Add(TablePlaces);
DS.Tables.Add(TableHorizons);
DS.Relations.Add(TablePlaces.Columns["Name"],
TableHorizons.Columns["parent_key"]);
}
public List<Place> BuilsListPlace()
{
TableHorizons.Clear();
TablePlaces.Clear();
using (DbCommand Command = newConnectionNewCommand())
{
Command.CommandText = "SELECT * FROM places ORDER BY Name"
fill(TablePlaces, Command);
Command.CommandText = "SELECT * FROM horizons ORDER BY parent_key,pointX";
fill(TableHorizons, Command);
Command.Connection.Dispose();
}
return (from DataRow dr in TablePlaces.Rows
select newPlace(dr)).ToList();
}
void fill(TableDB t ,DbCommand Command)
{
using (var da = newDataAdapter())
{
da.SelectCommand = Command;
da.MissingSchemaAction = MissingSchemaAction.Ignore;
da.Fill(t);
}
}
Place newPlace(DataRow dr)
{
Place result = new Place();
result.longitude=(float)dr["longitude"];
result.latitude=(float)dr["latitude"];
result.Name=(string)dr["Name"];
result.theHorizon=newHorizon(dr.GetChildRows(dr.Table.ChildRelations[0]));
return result;
}
Horizon newHorizon(DataRow[] Rows)
{
Horizon result = new Horizon();
result.points = new List<PointF>();
foreach(DataRow dr in Rows)
result.points.Add(new PointF((float)dr["pointX"],(float)dr["pointY"]);
return result;
}