3)數據行DynamicDataRow.cs
~~~
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MEntities
{
?? [Serializable]
?? public partial class DynamicDataRow
?? {
?????? public List<DynamicDataField> DataFields { get; private set; }
?????? public DynamicDataRow()
?????? {
?????????? DataFields = new List<DynamicDataField>();
?????? }
?? }
??
}
~~~
共享代碼部分:DynamicDataRow.Shared.cs
~~~
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MEntities
{
?? public partial class DynamicDataRow
?? {
?????? public DynamicDataField this[string FieldName]
?????? {
?????????? get
?????????? {
?????????????? DynamicDataField theField = null;
?????????????? foreach (var fld in DataFields)
?????????????? {
?????????????????? if (fld.FieldName == FieldName)
?????????????????? {
?????????????????????? theField = fld;
?????????????????????? break;
?????????????????? }
?????????????? }
?????????????? return theField;
?????????? }
?????? }
?????? public DynamicDataField this[int Index]
?????? {
?????????? get
?????????? {
?????????????? return DataFields[Index];
?????????? }
?????? }
?? }
??
}
~~~
4)數據表:
~~~
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MEntities
{
?? [Serializable]
?? public partial class DynamicDataTable
?? {
?????? public List<DynamicDataRow> Rows { get; private set; }
?????? public string TableName { get; set; }
?????? public List<DynamicDataColumn> Columns { get; private set; }
?????? public DynamicDataTable()
?????? {
?????????? Rows = new List<DynamicDataRow>();
?????????? Columns = new List<DynamicDataColumn>();
?????? }
?? }
}
~~~
數據表共享代碼部分:DynamicDataTable.Shared.cs
~~~
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MEntities
{
?? public partial class DynamicDataTable
?? {
?????? public DynamicDataColumn this[string FieldName]
?????? {
?????????? get
?????????? {
?????????????? DynamicDataColumn theCol = null;
?????????????? foreach (var col in Columns)
?????????????? {
?????????????????? if (col.FieldName == FieldName)
?????????????????? {
?????????????????????? theCol = col;
?????????????????????? break;
?????????????????? }
?????????????? }
?????????????? return theCol;
?????????? }
?????? }
?????? public DynamicDataColumn this[int Index]
?????? {
?????????? get
?????????? {
?????????????? return Columns[Index];
?????????? }
?????? }
?? }
}
~~~
實體的組織原則:
A)盡可能簡單,外部程序集依賴應盡可能少,這樣任何其它層都可以引用它,也便于穿越通信層,畢竟實體只是數據的載體;
B)索引器無法自動到達客戶端,索引器構建主要是為了客戶端綁定的時候提供一致的語法和語義;
C)如果實體有繼承體系,那么索引器可能無法共享到客戶端,這個時候可以直接把代碼添加到客戶端中即可,注意命名空間要保持與服務器一致。