首页 新闻 会员 周边

[SOS] ADO.NET ENtity 操作存储过程,查询数据

0
悬赏园豆:10 [已解决问题] 解决于 2008-10-28 12:21

利用存储过程进行查询,仅查询了部分字段(声明:查询所有字段时正常),出现如下错误,请求高人指教,先行谢过了。

报错:数据读取器与指定的“DRCNet.DMS.CMS.Model.Customers”不兼容。某个类型为“CustomerID”的成员在同名的数据读取器中没有对应的列。

报错指示代码:return base.ExecuteFunction<Customers>("PR_SearchCustomer", operatingSystemIDParameter, databaseIDParameter, pastUserParameter);

问题补充: 存储过程: CREATE PROCEDURE [dbo].[PR_CustomerSearch] @AreaID int, @IndustryID int, @ContractNo nvarchar(128), @CustomerName nvarchar(128), @CustomerTypeID int, @UpdateWayID int, @OperatingSystemID int, @DatabaseID int, @PastUser int AS select CustomerName, (select UpdateWayName from dbo.UpdateWay Where (dbo.Customers.UpdateWayID=UpdateWayID)) AS UpdateWayName, ContractStartDate,ContractEndDate, (select ContactRecord=ContactName+';'+ContactPhone+';'+ContactPhone from dbo.Contacts Where (dbo.Customers.CustomerID=CustomerID) and (ContactTypeID=1)) AS ContactRecord, LastUpdatedDate from Customers where (@AreaID=0 or AreaID=@AreaID) and (@IndustryID=0 or IndustryID=@IndustryID) and (@ContractNo='' or ContractNo like '%' +@ContractNo + '%' ) and (@CustomerName='' or CustomerName like '%' +@CustomerName+'%') and (@CustomerTypeID=0 or CustomerTypeID=@CustomerTypeID) and (@UpdateWayID=0 or UpdateWayID=@UpdateWayID) and (@OperatingSystemID=0 or OperatingSystemID=@OperatingSystemID) and (@DatabaseID=0 or DatabaseID=@DatabaseID) --and --(@RecordStatus=0 or RecordStatus=@RecordStatus) --and --(@Sales='' or Sales like '%'+@Sales+'%') and ( @PastUser =0 or ( (@PastUser=1 and ContractEndDate<getdate()) or (@PastUser=2 and ContractEndDate>=getdate()) ) ) GO
mayixue的主页 mayixue | 初学一级 | 园豆:29
提问于:2008-10-22 13:40
< >
分享
最佳答案
0

存储过程有没有查询CustomerID?存储过程具体怎么写的?

搜索出的表只有以下几列:
CustomerName,
UpdateWayName,
ContractStartDate,
ContractEndDate,
ContactRecord,
LastUpdatedDate
并没有CustomerID。
select 中加入CustomerID就可以了

小妮子 | 菜鸟二级 |园豆:410 | 2008-10-22 13:52
其他回答(1)
2

我今天也遇到了类似的错误 不过我的是数据库列名和Entity类的属性名不一致, 如数据库列名为:ID  实体类属性名为:UserID  我的解决方法是 为查询列名指定别名 如 ID as UserID   但感觉这样不是太好 那位知道更好的方法 麻烦告知一下 谢谢

代码哥 | 园豆:187 (初学一级) | 2012-04-09 15:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册