Anonymous type result from sql query execution entity framework

You have to use raw Sql for that, the entitity framework SqlQuery<T> will only work for objects with known types. here is the method I use : public static IEnumerable<dynamic> DynamicListFromSql(this DbContext db, string Sql, Dictionary<string, object> Params) { using (var cmd = db.Database.Connection.CreateCommand()) { cmd.CommandText = Sql; if (cmd.Connection.State != ConnectionState.Open) { cmd.Connection.Open(); } … Read more

Convert anonymous type to class

Well, you could use: var list = anBook.Select(x => new ClearBook { Code = x.Code, Book = x.Book}).ToList(); but no, there is no direct conversion support. Obviously you’ll need to add accessors, etc. (don’t make the fields public) – I’d guess: public int Code { get; set; } public string Book { get; set; } … Read more

Anonymous TABLE or VARRAY type in Oracle

Providing you’re not scared of explicitly referencing the SYS schema there are a few. Here are some I use quite often (well odcivarchar2list not so much, as it chews up a lot of memory: for strings I prefer dbms_debug_vc2coll). SQL> desc sys.odcinumberlist sys.odcinumberlist VARRAY(32767) OF NUMBER SQL> desc sys.odcivarchar2list sys.odcivarchar2list VARRAY(32767) OF VARCHAR2(4000) SQL> desc … Read more

Creating an anonymous type dynamically? [duplicate]

Only ExpandoObject can have dynamic properties. Edit: Here is an example of Expand Object usage (from its MSDN description): dynamic sampleObject = new ExpandoObject(); sampleObject.TestProperty = “Dynamic Property”; // Setting dynamic property. Console.WriteLine(sampleObject.TestProperty ); Console.WriteLine(sampleObject.TestProperty .GetType()); // This code example produces the following output: // Dynamic Property // System.String dynamic test = new ExpandoObject(); ((IDictionary<string, … Read more

C# ‘dynamic’ cannot access properties from anonymous types declared in another assembly

I believe the problem is that the anonymous type is generated as internal, so the binder doesn’t really “know” about it as such. Try using ExpandoObject instead: public static dynamic GetValues() { dynamic expando = new ExpandoObject(); expando.Name = “Michael”; expando.Age = 20; return expando; } I know that’s somewhat ugly, but it’s the best … Read more

Accessing constructor of an anonymous class

From the Java Language Specification, section 15.9.5.1: An anonymous class cannot have an explicitly declared constructor. Sorry 🙁 EDIT: As an alternative, you can create some final local variables, and/or include an instance initializer in the anonymous class. For example: public class Test { public static void main(String[] args) throws Exception { final int fakeConstructorArg … Read more