I am using .net framework 3.5 framework & for database operations entity framework. So, to fetch the data i am using LINQ queries & returns a resultset in a list.
e.g
public class Emp
{
public int CD{get;set;}
public string Name{get;set;}
}
public List<Emp> GetServTypeForPromotionDue()
{
return (from a in Context.TableName
select new Emp{ a.CD, a.NAME });
}
I am planning to migrate from 3.5 to 4.0. I have heard about dynamic keyword in .net 4.0. Can i make use of ‘dynamic’ keyword in order to remove the Class Emp & without creating Anonymous methods?
You could use
dynamicfor this (e.g. returningList<dynamic>, and building anExpandoObjectin the select clause), but I wouldn’t recommend it. You’d lose compile-time type safety, Intellisense etc for little benefit. What do you believe you’d gain from usingdynamic? Just removing a few lines of code?EDIT: Example of using dynamic:
Or…