zengcheng / codesmith

Automatically exported from code.google.com/p/codesmith
0 stars 0 forks source link

Extended Properties of Functions cause errors in VB.NET #609

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a Plinqo Project for VB.NET and include Functions
SQL DB should have at least 1 SP returning a value.

What is the expected output? 
No errors...
What do you see instead?
the "new" extended property return: is causing errors in VB.NET:

<return: System.Data.Linq.Mapping.Parameter(DbType := "int")> _
or 
<return: System.Data.Linq.Mapping.Parameter(DbType := "datetime")> _

VS2010 complains that "Keyword is not a valid Identifier" (for "return") this 
error is causing xxx of errors.
When I delete the Return row, the errors are gone.

What version of the product are you using?
Codesmith 6.0 Release candidate and Plinqo Nightly Build  2385 

Original issue reported on code.google.com by schaffn...@GMX.de on 21 Nov 2011 at 4:39

GoogleCodeExporter commented 9 years ago
Additionally in LinqEntityBase.Generated

I have got an issue inside the Function:
Protected Shared Function Detach(Of TEntity As LinqEntityBase) 

with:
LateBinder.SetField(entitySet, "isLoaded", true)

VS2010 claims:
Error   19  'LateBinder' is not declared. It may be inaccessible due to its 
protection level.   C:\Development\Visual Studio 
2010\Projects\WindowsApplicationTest\TEST.Data\LinqEntityBase.Generated.vb  112 1
3   TEST.Data

Original comment by schaffn...@GMX.de on 22 Nov 2011 at 10:07

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
In C# LinqEntityBase.Generated.cs
is:
using CodeSmith.Core.Reflection

but VS 2010 states:
Error   8   The type or namespace name 'Core' does not exist in the namespace 
'CodeSmith' (are you missing an assembly 
reference?) C:\Development\CodeSmith\Templates\PLINQO\Nrg2390_C#\Test.Data\LinqE
ntityBase.Generated.cs

this import is missing in VB.NET

which might cause the problem with "LateBinder"

Original comment by schaffn...@GMX.de on 23 Nov 2011 at 10:12

GoogleCodeExporter commented 9 years ago
OK I investigated the first issue. the Syntax needs to be changed for VB.NET
I will add an example:

Plinqo Syntax:
        ''' <summary>Method that is mapped to the dbo.fn_iso_week_number database procedure.</summary>
        ''' <returns></returns>
        <System.Data.Linq.Mapping.Function(Name:="dbo.fn_iso_week_number", IsComposable:=true)> _
        <return: System.Data.Linq.Mapping.Parameter(DbType := "int")> _
        <System.CodeDom.Compiler.GeneratedCode("CodeSmith", "6.0.0.0")> _
        Public Function FnIsoWeekNumber( _
            <System.Data.Linq.Mapping.Parameter(Name:="@date", DbType:="datetime")> ByVal [Date] As Date?) As Integer
            Dim methodInfo = DirectCast(System.Reflection.MethodInfo.GetCurrentMethod(), System.Reflection.MethodInfo)
            Dim result As System.Data.Linq.IExecuteResult = Me.ExecuteMethodCall(Me, methodInfo, [Date])
            Return (DirectCast((result.ReturnValue),Integer))
        End Function

Correct VB.NET Syntax:

        ''' <summary>Method that is mapped to the dbo.fn_iso_week_number database procedure.</summary>
        ''' <returns></returns>
        <System.Data.Linq.Mapping.Function(Name:="dbo.fn_iso_week_number", IsComposable:=True)> _
        <System.CodeDom.Compiler.GeneratedCode("CodeSmith", "6.0.0.0")> _
        Public Function FnIsoWeekNumber( _
            <System.Data.Linq.Mapping.Parameter(Name:="@date", DbType:="datetime")> ByVal [Date] As Date?) As <System.Data.Linq.Mapping.Parameter(DbType:="int")> Integer
            Dim methodInfo = DirectCast(System.Reflection.MethodInfo.GetCurrentMethod(), System.Reflection.MethodInfo)
            Dim result As System.Data.Linq.IExecuteResult = Me.ExecuteMethodCall(Me, methodInfo, [Date])
            Return (DirectCast((result.ReturnValue), Integer))
        End Function

The Attribute needs to be removed:
 <return: System.Data.Linq.Mapping.Parameter(DbType := "int")> _

Instead we would need it as additional info of the Function Return:
) As <System.Data.Linq.Mapping.Parameter(DbType:="int")> Integer

Would be nice to get some feedback by the community

Original comment by schaffn...@GMX.de on 23 Nov 2011 at 10:41

GoogleCodeExporter commented 9 years ago
Hello,

Is there any chance you could attach a sample stored procedure that will 
reproduce this behavior so we can verify and test this change. Also were you 
targeting the .NET Client profiles at any time?

Original comment by bniemyjski on 28 Nov 2011 at 2:07