NorthwindDataContext db=new NorthwindDataContext();
            var custs=db.Customers;
            XElement xelement = new XElement("Customers",
                from cust in custs
                where cust.Country == "USA"
                select new XElement("Customer",
                    from property in cust.GetType().GetProperties()
                    where property.Name!= "Orders"
                    select new XAttribute(property.Name, (property.GetValue(cust, null) == null ? "" : property.GetValue(cust, null)).ToString()),
                    new XElement("Orders",
                        from order in cust.Orders
                        select new XElement("Order",order.ShipCity, new XAttribute("OrderId",order.OrderID)))
                    ));就是上面这段代码,提示说:成員存取 'System.Reflection.MemberInfo' 的 'System.String Name' 在型別 'System.Reflection.PropertyInfo[] 上不合法。

解决方案 »

  1.   

    建议  linq 只负责从数据库 捞数据
    至于转换成需要的类型之类的操作 最好在别的地方做
      

  2.   

    也没看明白
    大概也许好象可能差不多是这个cust没有"name"属性。
    你看下cust的定义吧,如果没问题就看看数据库里有没有这样的记录,保证取到的不是空值。
      

  3.   


    我没有NorthWind,我不用Linq TO sql的,你就不能把NorthwindDataContext相关声明贴出来吗?明明是自动产生的。