linq - C# Covariance issue -
I had a linq-to-sql generated domain unit that I had inserted in the appropriate interface like this:
Public IEnumerable & lt; IApplication & gt; GetApplications () {Usage (var dc = new LqDev202DataContext ()) {return dc.ZApplications.Cast & lt; IApplication & gt; (). ToList (); }}
Although I changed the name of the linq-to-sql table without touching my partial class and still compiled code.
The list contained the correct amount of elements, but they were all null.
Do I need to write a helpful method to make sure that it will work, or is it safe to do so in a simple time to 3.5.4?
You can also use it to cast with conversion if needed:
public static IEnumerable & lt; TDest & gt; Cast All & lt; TItem, TDest & gt; (This IEnumerable & lt; TItem & gt; Items) {var p = expression. Parameters (type (TItem), "i"); Var c = expression Convert (P, Typef (TDest)); Var ex = Expression.Lambda & lt; Func & lt; TItem, TDest & gt; & Gt; (C, P) .Compile (); Foreign item (different item in item) {yield returns pre (item); }}
to
Comments
Post a Comment