简体   繁体   中英

Reading properties of list in Entity Framework

I am using EF using Linq to create a list zz, which is working fine.

var zz = (from m in z
          join n in t_bb
          on m.id equals n.id into output
          from j in output.DefaultIfEmpty()
          select new
          {
              s_Id = m.s1,
              name = j.Name,
              main_Date = m.mDate,
          });

return zz;

When I access this in a method using following code

inputOutput io = new inputOutput();
var n = io.readWrite1(); 
foreach (var i in n)
{
    i.name;
    //Complier gives error Type or namespace i could not be found at i.name
    Console.WriteLine(i);
}

This all works fine I can get the listing in console. Problem is when i try to access any properties in the list i.name or any, I cant get any, no IntelliSense, when i hover mouse on i it says "Type and namespace i could not be found."

Unfortunately c# and visual studio doesn't work very well with anonymous classes that crosses method boundaries. You have to make it into a concrete class or tuple in order to get intellisense in your calling method.

Another option is to use dynamic (n.Cast< dynamic >()) - but that still won't give you intellisense - however you will be able to use the property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM