读书人

哪位高手帮忙看下这段代码,《Linq高级

发布时间: 2012-03-19 22:03:05 作者: rapoo

谁帮忙看下这段代码,《Linq高级编程》中的实例无法调试通过

C# code
public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {        }    }    public class AdventureWorks : DataContext    {        public AdventureWorks(string connection)            : base(connection)        {        }        public IEnumerable<OrderBySalesPersonID> SalesOrders([Parameter(DbType="int")] int salesPersonID)        {            /*这里出现提示:错误    3    非泛型 方法“System.Data.Linq.DataContext.ExecuteMethodCall(object, System.Reflection.MethodInfo, params object[])”不能与类型实参一起使用    D:\Source\AppTest\Test4\Form1.cs    39    25    Test4*/            return this.ExecuteMethodCall<OrderBySalesPersonID> (this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), salesPersonID);        }    }    [Table(Name="SalesPersonOrders")]    public partial class OrderBySalesPersonID    {        private int _productID;        private string _productName;        private int _salesPersonID;        private string _firstName;        private string _middleName;        private string _lastName;        private decimal _unitPrice;        [Column(Name="ProductID",Storage="_productID",DbType="int")]        public int ProductID        {            get            {                return this._productID;            }            set            {                if((this._productID != value))                {                    this._productID = value;                }            }        }        [Column(Name="Name",Storage="_productName",DbType="nvarchar(50)")]        public string ProductName        {            get            {                return _productName;            }            set            {                if((this._productName != value))                {                    this._productName = value;                }            }        }        [Column(Name="SalesPersonID",Storage="_salesPersonID",DbType="int")]        public int SalesPerson        {            get            {                return this._salesPersonID;            }            set            {                if((this._salesPersonID != value))                {                    this._salesPersonID = value;                }            }        }        [Column(Name="FirstName",Storage="_firstName",DbType="nvarchar(50)")]        public string FirstName        {            get            {                return _firstName;            }            set            {                if ((this._firstName != value))                {                    this._firstName = value;                }            }        }        [Column(Name="MiddleName",Storage="_middleName",DbType="nvarchar(50)")]        public string MiddleName        {            get            {                return _middleName;            }            set            {                if ((this._middleName != value))                {                    this._middleName = value;                }            }        }        [Column(Name="LastName",Storage="_lastName",DbType="nvarchar(50)")]        public string LastName        {            get            {                return _lastName;            }            set            {                if ((this._lastName != value))                {                    this._lastName = value;                }            }        }        [Column(Name="UnitPrice",Storage="_unitPrice",DbType="decimal")]        public decimal UnitPrice        {            get            {                return _unitPrice;            }            set            {                if ((_unitPrice != value))                {                    _unitPrice = value;                }            }        }    } 



刚接触linq不知道这个错误怎么解决
发现这本书中的错误还有点多,不知道是不是我自己的问题:-)

麻烦高手们帮我解决一下这个实例中的错误提示,多谢!

[解决办法]
这个方法不支持泛型
ExecuteMethodCall<OrderBySalesPersonID>()

去掉<OrderBySalesPersonID>试试
[解决办法]
MSDN里这个方法的签名

protected internal IExecuteResult ExecuteMethodCall(
Object instance,
MethodInfo methodInfo,
Object[] parameters
)

读书人网 >.NET

热点推荐