Country 是Linq to sql 的一个实体类
如果我们按这个代码运行的话就会得到The mapping of interface member IDisplayOrder.ID is not supported.
注意看Exchange的代码
一个方法是先where 后FirstOrDefault 这个方法可以使用。而如果直接用FirstOrDefault 的话就会有错了
Code
public class ABC<T> : AbstractBiz where T : class, IDisplayOrder
{
public ABC()
: base()
{ }
public ABC(WebDC dc)
: base(dc)
{ }
public void Exchange(int firstID,int secondID)
{
Table<T> table = DC.GetTable<T>();
T first = table.Where(it=>it.ID==firstID).FirstOrDefault();
int temp = first.DisplayOrder;
T second = table.FirstOrDefault(it => it.ID ==secondID);
first.DisplayOrder = second.DisplayOrder;
second.DisplayOrder = temp;
}
}
Code
public interface IDisplayOrder
{
int ID { get; set; }
int DisplayOrder { get; set; }
}
partial class Country:IDisplayOrder
{
}
WebDC dc = new WebDC(DataObject.connstr);
ABC<Country> biz = new ABC<Country>(dc);
biz.Exchange(20,21);
dc.SubmitChanges();