如何从C#中的函数返回Generic.List <Anonymoustype>

nav*_*een 0 c# linq asp.net linq-to-sql

ASP.NET 3.5 C#
我正在使用Linq加入两个表.
表名是MapAssets和ExitPoint.
在数据库中,他们与'有关系'有关

我正在我的BLL中编写一个函数来返回连接表

        public List<ExitPoints> GetExitPointDetailsByProjectID(int iProjectID)
        {
            ctx = new CoreDBDataContext();
            var exitPointDetails = from ma in ctx.MapAssets
                                   join ep in ctx.ExitPoints
                                   on ma.MapAssetID equals ep.MapAssetID
                                   where ma.ProjectID == iProjectID
                                   select new
                                   {
                                       //would like to have data from both tables here
                                       ctx.MapAssets,
                                       ctx.ExitPoints
                                   };
            return exitPointDetails.ToList();
        }
Run Code Online (Sandbox Code Playgroud)

这显然不起作用.而且我根本不知道该返回什么.
我对返回的所有约束都是能够绑定到gridview.
这是正确的方法吗?或者最新的方式是什么?

dig*_*All 6

你不能,或更好的,唯一的办法是回到他们在一个盒装Listobject,但是这个非常复杂的事情,因为你不能将它们转换成任何类型的(当然是匿名的),你只能通过访问其属性反射....

在这种情况下,我强烈建议您创建一个自定义类.

编辑:

在旁注...
如果你使用.net 4,事情会更容易,因为你可以返回dynamicType而不是object(看看这个链接看看dynamic的简化),但我更喜欢创建一个自定义类.