SPToCore icon indicating copy to clipboard operation
SPToCore copied to clipboard

Functions

Open amccool opened this issue 4 years ago • 6 comments

extract Function as well

amccool avatar Jun 08 '20 16:06 amccool

Hi ! Do you need to work with functions ? I've never used them in linToSql and I even don't know if they can be imported...

DarioN1 avatar Jun 25 '20 11:06 DarioN1

I have several databases where the DBA has created many user defined functions, including TVF and SVF.

amccool avatar Jun 26 '20 03:06 amccool

I have no clue how to extract functions. However the following is what I hand coded. Perhaps getting the list of functions, and the return types and args could help generate this?

The Scalar Valued Functions look like this:

        [DbFunction("FnGetPatternPositionColors")]
        public static string FnGetPatternPositionColors(Nullable<long> patternId, Nullable<int> lightPositionId)
        {
            throw new NotSupportedException("Direct calls are not supported.");
        }

The TVF's look like this:

        public IQueryable<FnGetEscalationByTypeResult> FnGetEscalationByType(long escalationChainId, long escalationTypeId) 
            => 
            Query<FnGetEscalationByTypeResult>().FromSqlInterpolated($"select * from FnGetEscalationByType({escalationChainId}, {escalationTypeId})");

and require this for the returned table

            modelBuilder.Entity<FnGetEscalationByTypeResult>().HasNoKey();

amccool avatar Jun 26 '20 04:06 amccool

Hi, I've checked and yes... The old LinkToSql supports user defined functions... To be honest, I've never had the necessity to use them in projects, I have used tons of stored procedure but zero functions...

DarioN1 avatar Jun 26 '20 08:06 DarioN1

If you can point me to the code that LinkToSql uses to interrogate the db I'll see if I can create a PR for you.

amccool avatar Jun 26 '20 16:06 amccool

is this project available? https://github.com/DarioN1/SPToCore/blob/master/SPToCore.sln#L8

amccool avatar Jun 27 '20 19:06 amccool