Generics: Type cannot be implicitly converted.
I have the following classes:

     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;
            }
        }

 

They all compile nicely but when trying to apply this extension method:

 

     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;
            }

Like this:

 

    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);
                }
            }

I get a compilation error 

> The type 'WaybillDocument' cannot be used as type parameter 'T' in the
> generic type or method
> 'LinqExtensions.ToEntitySetFromInterface<T,U>(System.Collections.Generic.IList<U>)'.
> There is no implicit reference conversion from 'WaybillDocument' to
> 'IWaybillDocument'

with

    waybills.ToEntitySetFromInterface<WaybillDocument, IWaybillDocument>()

underlined. Why is that when it clearly inherits the interface?
Generics: Type cannot be implicitly converted.
===

I have the following classes:

     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;
            }
        }

 

They all compile nicely but when trying to apply this extension method:

 

     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;
            }

Like this:

 

    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);
                }
            }

I get a compilation error 

> The type 'WaybillDocument' cannot be used as type parameter 'T' in the
> generic type or method
> 'LinqExtensions.ToEntitySetFromInterface<T,U>(System.Collections.Generic.IList<U>)'.
> There is no implicit reference conversion from 'WaybillDocument' to
> 'IWaybillDocument'

with

    waybills.ToEntitySetFromInterface<WaybillDocument, IWaybillDocument>()

underlined. Why is that when it clearly inherits the interface?