문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top