나는 다음과 같은 클래스가 :
항목만들기 클래스 구조는 문제
public class Item : INotifyPropertyChanged, IDataErrorInfo
{
private int? id;
public int? ID
{
get
{ return id; }
set
{ id = value; }
}
private string name;
public string Name
{
get
{ return name; }
set
{
if (value != name)
{
ClearError("Name");
if (string.IsNullOrEmpty(value) || value.Trim() == "")
SetError("Name", "Required Value");
name = value;
}
}
}
private List<MedicineComposition> medicineCompositions;
public List<MedicineComposition> MedicineCompositions
{
set { medicineCompositions = value; }
get { return medicineCompositions; }
}
}
MedicineComposition
public class MedicineComposition : INotifyPropertyChanged, IDataErrorInfo
{
private int? id;
public int? ID
{
get
{ return id; }
set
{ id = value; }
}
private Item item;
public Item Item
{
get
{ return item; }
set
{
if (item != value)
{
ClearError("Item");
if (value == null)
SetError("Item", "Required Value");
item = value;
}
}
}
private Component component;
public Component Component
{
get
{ return component; }
set
{
if (component != value)
{
ClearError("Component");
if (value == null)
SetError("Component", "Required Value");
component = value;
}
}
}
}
만 id
및 Name
하고있다 구성 요소을 팔로우 인 데이터베이스에서 데이터를 가져오고 내 개체의 목록을 만들 g 기능 : MedicalCompositions
public static List<MedicineComposition> GetAllByItem(Item i)
{
List<MedicineComposition> MyMedicineCompositions = new List<MedicineComposition>();
SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString);
SqlCommand com = new SqlCommand("sp_Get_ByItemID_MedicineComposition", con);
com.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter pr = new SqlParameter("@ID", i.ID);
com.Parameters.Add(pr);
try
{
con.Open();
SqlDataReader rd = com.ExecuteReader();
while (rd.Read())
{
MedicineComposition m = new MedicineComposition() { };
if (!(rd["ID"] is DBNull))
m.ID = Int32.Parse(rd["ID"].ToString());
if (!(rd["ComponentID"] is DBNull))
m.Component = Component.GetByID(Int32.Parse(rd["ComponentID"].ToString()));
m.Item = i;
MyMedicineCompositions.Add(m);
}
rd.Close();
}
catch
{
MyMedicineCompositions = null;
}
finally
{
con.Close();
}
return MyMedicineCompositions;
}
에 Item
클래스
public static List<Item> GetAllItems
{
get
{
List<Item> MyItems = new List<Item>();
SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString);
SqlCommand com = new SqlCommand("sp_Get_All_Item", con);
com.CommandType = System.Data.CommandType.StoredProcedure;
try
{
con.Open();
SqlDataReader rd = com.ExecuteReader();
while (rd.Read())
{
Item i = new Item();
if (!(rd["ID"] is DBNull))
i.ID = System.Int32.Parse(rd["ID"].ToString());
i.Name = rd["Name"].ToString();
i.MedicineCompositions = MedicineComposition.GetAllByItem(i);
MyItems.Add(i);
}
rd.Close();
}
catch
{
MyItems = null;
}
finally
{
con.Close();
}
return MyItems;
}
에
GetAllByItem을 GetItems를 그것이 당신을 할 수 있기 때문에 mvvm
를 사용하는 등의 datatable
대신 개체를 다루지 만, 이전 구조 도형을 사용할 때 다음 문제가 발생합니다.
- 은 내가
GetAllItems
를 호출 할 때 그래서 난 성능 저하가 데이터베이스에Item
표에서 적어도 1,000 레코드가 특히하지 않을 경우 로컬 컴퓨터의 데이터베이스. - 는 내가 가지고있는 문제이고 그래서가 다시
내 질문 둔화에 시작 화면, 그것은 시간을 소요 할 때Items
를로드하지만 난GetAllItems
을 기억해야Item
테이블에 각 업데이트에 매체 성능 - 을 시도 클래스, 그리고 생성이 나는 사용자가 조성되지도 많은 천, 한 눈에 모든 1000 개 항목을 볼 필요가 있다고 생각하지 말아
mvvm
db에 많은 양의 데이터가있는 경우 모두 가져 오는 것이 항상 느려지므로 그 방법이 있습니다. 여기에있는 질문은 모든 데이터를 즉시 필요로 하는가? 필요할 때 데이터를로드 할 수 있습니다. 청크로 데이터를로드 할 수 있으므로 UI를 차단하지 않거나 성능을 너무 많이 올릴 수 없습니다. 당신은 당신이 가장 필요로하는 것을 여기에서 계산할 필요가 있고 당신이 더 프로그램하는 것에 따라 계산해야합니다. –
답변 코드가 업데이트되었습니다. –