Cannot call TVF with Linq

Posts   
 
    
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 16-Jan-2014 03:33:15   

I am using self servicing with two classes. I downloaded and installed the Jan 14, 2014 release date (build Nov 26, 2013). It contains 4.1.14.110 versions of the dlls. Everything compiles and function normally.

I mapped a TVF into my project.
It appears under 'Table Valued Function Calls' in the designer. It also created a TypedView for the result of my function call - that typed view appears correct. After creating the call definition, I originally got a validation error, because the 'return element' was not defined - no problem, I just selected the typedview you created for me.

I now generate code. Under TypedViewClasses, I get the typed view for the function result. Under FactoryClasses, I get TvfCallFactory and it creates the factory for this call.

I do NOT get anything else - the LinqMetaData.cs file does not have an entry so that I can reference my TVF. According to the docs, I should be able to do metaData.MyTableValueFunction(), but that does not work as that member does not contain TVF. I also cannot find any code that was generated to support this.

Please advise.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Jan-2014 07:00:30   

If you want to use a TVF on linq, it should be mapped onto an entity. As explained in the docs .

Otherwise you must use QuerySpec. See this documentation section.

David Elizondo | LLBLGen Support Team
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 16-Jan-2014 08:45:00   

Well, I had already read that. I have now read it like 5 more times.

So, you are saying that if the result of the function HAPPENS to be the same structure as an existing Entity, then it will show up under Linq?

IMHO, That is not 'explained' very well at all. This is also a pretty limiting factor as very few of my TVF would return an existing Entity. cry

Really need to have this as a Linq option even though it maps to a typedview (that designer created). Of course we need typedviews as Linq items without mapping to an entity (or as I have suggested even supporting 'read only' entities - which are essentially views - but with full linq capabilities).

Anyway, I am just restating many of the suggestions I have already made to Otis smile

Thanks for your help.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 16-Jan-2014 11:06:34   

WayneBrantley wrote:

Well, I had already read that. I have now read it like 5 more times.

So, you are saying that if the result of the function HAPPENS to be the same structure as an existing Entity, then it will show up under Linq?

No, you have to set the return type of the TVF call in the designer to an existing entity. This is possible, have an entity mapped onto a table and also on a tvf call result. The mappings for the tvf call result are done with the tvf call, the mappings to the table (normal mappings) are done in the normal mappings tab of the entity.

IMHO, That is not 'explained' very well at all. This is also a pretty limiting factor as very few of my TVF would return an existing Entity. cry

Linq only works with entities, so if a tvf call has to be called in linq, it has to return an entity. It's how the linq engine works (and it takes a tremendous amount of work to change that, so we're not doing that soon)

Really need to have this as a Linq option even though it maps to a typedview (that designer created). Of course we need typedviews as Linq items without mapping to an entity (or as I have suggested even supporting 'read only' entities - which are essentially views - but with full linq capabilities).

We'll see what we can do. Read only entities are planned for v4.2, we haven't designed that feature yet, but you do bring up a good point: if the entity is the return type of a TVF, then it doesn't have to be mapped onto a table/view as it's already mapped, making it effectively a readonly entity.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 16-Jan-2014 16:58:20   

Thanks for your consideration.

In addition if the TVF does not map to an entity........

When I create a call definition - it created a typed view and it maps to that and that is not in linq. What would be nice is to have it create a 'read only' entity (a typed view) and have it map to that.

Essentially I want to do most things with linq.

Thanks again guys!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 16-Jan-2014 17:40:33   

Good point. We'll take that into consideration when we'll work on readonly entities, thanks for the ideas simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 28-Oct-2014 16:25:46   

Dont use old threads...I know the rule, but if it is my thread and I have the exact same issue can I re-use it? simple_smile

I am now using 4.2 and it is supposed to support the above the best I can tell. I mapped my TVF and it created a new typedview for me. I marked it as poco.

The generated code now does exactly as I said above...what am I missing?

Note, I can select 'TypedDataTable' as the output and I get the typedview, so I guess I will use that for now.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 28-Oct-2014 16:31:17   

WayneBrantley wrote:

Dont use old threads...I know the rule, but if it is my thread and I have the exact same issue can I re-use it? simple_smile

I am now using 4.2 and it is supposed to support the above the best I can tell. I mapped my TVF and it created a new typedview for me. I marked it as poco.

The generated code now does exactly as I said above...what am I missing?

You said more than one thing above, so what exactly are you referring at, could you give an example of what code you did expect?

A linq poco typedview is present as a method in the LinqMetaData:

var q = from o in metaData.GetOrdersForCustomerTV("ALFKI")
        where o.EmployeeId == 4
        select o;

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 28-Oct-2014 16:40:26   

I mapped a TVF into my project. It appears under 'Table Valued Function Calls' in the designer. It also created a TypedView for the result of my function call - that typed view appears correct. After creating the call definition, I originally got a validation error, because the 'return element' was not defined - no problem, I just selected the typedview you created for me.

I marked it as a LinqPoco

I now generate code. Under TypedViewClasses, I get the typed view for the function result. Under FactoryClasses, I get TvfCallFactory and it creates the factory for this call.

I do NOT get anything else - the LinqMetaData.cs file does not have an entry so that I can reference my TVF. According to the docs, I should be able to do metaData.MyTableValueFunction(), but that does not work as that member does not contain TVF. I also cannot find any code that was generated to support this.

Maybe I am missing a template in my definition or something?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 28-Oct-2014 16:48:30   

What build of the designer are you using? Could you try the latest build if it's not a recent one? The thing is that it might be related to an include template issue we had in earlier builds of the designer which could lead to an include template not being run and thus not generating the functions you need.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 28-Oct-2014 16:56:52   

4.2.18.427

I cannot update it right now, but will update to the latest shortly.

Was the bug fixed after the version I show I am running? (What template is it that causes this code to run - just want to make sure it shows as included)

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 28-Oct-2014 17:57:15   

4.2.18.427

What is the release date of the designer (help/about) ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 28-Oct-2014 20:38:35   

Bug was in the code generator + designer assemblies, so you need the last designer. The runtime isn't at fault here. simple_smile

It's the issue fixed on August 8th:

.lpt templates which are marked as 'includeOnly' and which can't stand on their own as a separate class could lead to a crash during code generation because the templates were still converted as separate classes for include into TDL templates.

This crash issue showed when testing it that the include templates didn't run in some cases. To be sure, I have verified it again that they do now, our generated code for out tests has the right methods for the TVF mapped typed views in Linq.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 29-Oct-2014 04:45:57   

The designer says version is "4.2 final". That seemed vague to me, so I gave you version number 4.2.18.427 from the exe of the designer, as the help|about seemed vague.

I downloaded and installed it again, still says the same thing. 4.2 final, however now the version number of the exe is 4.2.14.915the

That version number I gave you 4.2.18.427 was from the exe of the designer, as the help|about does not show anything else!!

Now the version number of the exe is 4.2.14.915

Anyway, the important thing is now code is generated! Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Oct-2014 09:27:07   

WayneBrantley wrote:

The designer says version is "4.2 final". That seemed vague to me, so I gave you version number 4.2.18.427 from the exe of the designer, as the help|about seemed vague.

The designer build date is in the about screen and in the window title bar

I downloaded and installed it again, still says the same thing. 4.2 final, however now the version number of the exe is 4.2.14.915the

That version number I gave you 4.2.18.427 was from the exe of the designer, as the help|about does not show anything else!!

Yes it does: 'Released on' and then a date, in help about. Same date as in the window title bar.

The version of the exe is less important for the designer, it's the build date.

Now the version number of the exe is 4.2.14.915 Anyway, the important thing is now code is generated! Thanks.

simple_smile

Frans Bouma | Lead developer LLBLGen Pro