我有以下课程:
public interface IWaybillDocument
{
long DocumentId { get; set; }
long BillingDocumentId { get; set; }
string ShipToName { get; set; }
byte AddressType { get; set; }
string City { get; set; }
string Country { get; set; }
string PostCode { get; set; }
string StateRegion { get; set; }
string Street1 { get; set; }
string Street2 { get; set; }
string Suburb { get; set; }
void MergeAddressing(Address address);
}
}
public class WaybillDocumentList : ERPListBase<IWaybillDocument>
{
public WaybillDocumentList() : base() { }
}
public partial class WaybillDocument : IWaybillDocument, INonrepudiable
{
public void MergeAddressing(Address address)
{
address.Street1 = this.Street1;
address.Street2 = this.Street2;
address.Suburb = this.Suburb;
address.City = this.City;
address.ZipCode = this.PostCode;
address.StateRegion = this.StateRegion;
address.Country = this.Country;
address.AddressKind = (AddressKind)this.AddressType;
}
}
它们都编译得很好,但是在尝试应用此扩展方法时:
public static EntitySet<T> ToEntitySetFromInterface<T, U>(this IList<U> source)
where T : class, U
{
var es = new EntitySet<T>();
IEnumerator<U> ie = source.GetEnumerator();
while (ie.MoveNext())
{
es.Add((T)ie.Current);
}
return es;
}
像这样:
public void InsertWaybills(WaybillDocumentList waybills)
{
try
{
;
this.Context.WaybillDocuments.InsertAllOnSubmit(waybills.ToEntitySetFromInterface<WaybillDocument, IWaybillDocument>());
this.Context.SubmitChanges();
}
catch (Exception ex)
{
throw new DALException("void InsertWaybills(WaybillList waybills) failed : " + ex.Message, ex);
}
}
我收到编译错误
类型“WaybillDocument”不能用作泛型类型或方法“LinqExtensions.ToEntitySetFromInterface(System.Collections.Generic.IList)”中的类型参数“T”。没有从“WaybillDocument”到“IWaybillDocument”的隐式引用转换
和
waybills.ToEntitySetFromInterface<WaybillDocument, IWaybillDocument>()
下划线。为什么它清楚地继承了接口?
更新:ERPListBase(删除细节)
public class ERPListBase<T> : List<T>
{
public ERPListBase()
: base() {}
}