包装 linq-to-sql 函数签名
我有一个存储函数,例如:
CREATE FUNCTION RegionContains
(
@RegionX float, @RegionY float, @RegionRadius float,
@ObjectX float, @ObjectY float
)
RETURNS bit
AS
BEGIN
DECLARE @IsContained bit
DECLARE @ObjectRadius real
SELECT @ObjectRadius = SQRT(POWER(@ObjectX - @RegionX, 2) + POWER(@ObjectY - @RegionY, 2))
IF @ObjectRadius <= @RegionRadius
RETURN 1
RETURN 0
END
GO
它需要 5 个浮点参数 - 但问题是,我的 C# 项目中有代表这些值的对象。
因此,我打开 Visual Studio 并将存储的函数拖到 DBML 设计器中,然后我得到了一个神奇的函数签名,其中包含所有这些 double
参数。有没有办法为此创建一个包装器,当我更新 DBML 时不会中断?我想创建一个接受两个类型参数的函数,从这些对象中提取相关值,然后将它们发送到存储过程 - 同时仍然允许从 linq 查询调用该包装函数。 VS 支持这个吗?
I have a stored function, such:
CREATE FUNCTION RegionContains
(
@RegionX float, @RegionY float, @RegionRadius float,
@ObjectX float, @ObjectY float
)
RETURNS bit
AS
BEGIN
DECLARE @IsContained bit
DECLARE @ObjectRadius real
SELECT @ObjectRadius = SQRT(POWER(@ObjectX - @RegionX, 2) + POWER(@ObjectY - @RegionY, 2))
IF @ObjectRadius <= @RegionRadius
RETURN 1
RETURN 0
END
GO
It takes 5 float parameters -- but the thing is, I have objects in my C# project which represent these values.
So I open up visual studio and drag the stored function into the DBML designer, and I get a magical function signature which has all of these double
parameters. Is there a way to create a wrapper for this that won't break when I update the DBML? I want to create a function which takes two typed arguments, that extracts the relevant values from those objects and then sends them to the stored procedure -- while still being allowed to call that wrapper function from a linq query. Does VS support this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
双击设计器。创建不会被覆盖的 C# 源文件。
所有生成的类都被标记为部分的,因此您只需在其中添加包装器/帮助器函数即可。这是一种很常见的做法,我也经常使用它。
更新
根据函数的用例,包装器可能无法在 Linq2SQL 查询中工作。如果这就是您所追求的,请告诉我。我会删除我的答案。
Double-click the designer. A C# source file be created that wont be overwritten.
All generated classes are marked partial, so you can just add your wrapper/helper functions in there. This is quite a common practice, and I tend to use it a lot.
Update
Depending on the use case of functions, a wrapper might not work in Linq2SQL queries. If this is what you are after, let me know. I'll delete my answer.