简体   繁体   English

读取实体框架中列表的属性

[英]Reading properties of list in Entity Framework

I am using EF using Linq to create a list zz, which is working fine. 我正在使用EF使用Linq创建一个列表zz,这工作正常。

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." 问题是,当我尝试访问列表i.name或任何属性中的任何属性时,我无法获得任何智能感知,当我将鼠标悬停在i上时,它显示“无法找到类型和命名空间”。

Unfortunately c# and visual studio doesn't work very well with anonymous classes that crosses method boundaries. 不幸的是,c#和visual studio对于跨越方法边界的匿名类不能很好地工作。 You have to make it into a concrete class or tuple in order to get intellisense in your calling method. 你必须把它变成一个具体的类或元组才能在你的调用方法中获得intellisense。

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. 另一个选择是使用动态(n.Cast <dynamic>()) - 但仍然不会给你intellisense - 但是你将能够使用该属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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