【发布时间】:2011-08-03 20:57:40
【问题描述】:
我有一些带有 linq2sql 类的遗留代码。 DataContext 类对存储过程的定义如下:
[Function(Name="dbo.sp_Goods_SelectBySection")]
public ISingleResult<sp_Goods_SelectBySectionResult> sp_Goods_SelectBySection([Parameter(Name="SectionId", DbType="Int")] System.Nullable<int> sectionId)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), sectionId);
return ((ISingleResult<sp_Goods_SelectBySectionResult>)(result.ReturnValue));
}
但是当我尝试在我自己的项目中创建相同的程序时,设计师会创建具有不同实现的程序:
[Function(Name="dbo.sp_Goods_SelectBySection")]
public int sp_Goods_SelectBySection([Parameter(Name="SectionId", DbType="Int")] System.Nullable<int> sectionId)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), sectionId);
return ((int)(result.ReturnValue));
}
而且我无法更改方法属性中的类型。
这是存储过程的代码。
ALTER PROCEDURE [dbo].[sp_Goods_SelectBySection]
(
@SectionId INT
)
AS
BEGIN
SET NOCOUNT ON;
SELECT
Goods.Id,
Goods.[Name],
TypeId,
Makerid,
Price,
[Description],
Term,
Types.Name AS TypeName,
Makers.Name AS MakerName,
GoodsImage.SmallImageUrl AS MainImageUrl,
Goods.IsDeleted,
Goods.Rang
FROM Goods
INNER JOIN Types ON (Types.Id = Goods.TypeId)
INNER JOIN Makers ON (Makers.Id = Goods.MakerId)
LEFT JOIN GoodsImage ON ( GoodsImage.GoodId = Goods.Id AND GoodsImage.IsMain = 1 AND GoodsImage.IsDeleted = 0 )
WHERE
Types.SectionId = @SectionId
AND Goods.IsDeleted = 0
ORDER BY Rang ASC
END
为什么?以及如何创建返回 ISingleResult 而不是 int 的过程?
请注意,我有很多这样的程序,我认为手动修改每个程序都不是好主意。
我猜是设计师的问题。因为我创建了新的测试项目,它工作正常。感谢所有帮助过我的人。尤其是安德拉斯·佐尔坦。
【问题讨论】:
-
你确定这是在你指向设计者的数据库中编译的过程的实际文本吗?
-
@JohnOpincar 是的,这是程序的实际文本。我在这两种情况下都使用相同的程序。
-
@JohnOpincar - 我支持你。 C#/Sql 块中的 SP 名称不匹配...
-
@Neir0 - 现在您已经更新了代码,以便所有名称都匹配;您能否尝试简单地从 L2S 设计器中删除 SP,然后从服务器资源管理器中再次将其拖回?
-
@Andras Zoltan 我刚刚复制了其他程序来提问。对不起。我编辑了问题。
标签: c# tsql linq-to-sql