1

テーブルとビューの定義を正常に作成できました。ルーチンのクラス定義を完成させようとしています。プロパティの定義をMSDNの情報と比較したところ、正しいようです。正常にコンパイルされますが、クエリを実行しようとすると、次の例外が発生します。

System.InvalidCastException がキャッチされました
  Message="指定されたキャストは無効です。"
  ソース="System.Data"
  スタックトレース:
       System.Data.SqlClient.SqlBuffer.get_Int32() で
       Read_Object(ObjectMaterializer`1) で
       System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() で
       System.Collections.Generic.List`1..ctor (IEnumerable`1 コレクション) で
       System.Linq.Enumerable.ToList[TSource](IEnumerable`1 ソース) で
       AMCRM.frmSystemCheck.DBInfoRoutines() で
  内部例外:

テーブル クラスは次のように定義されます。

<Table(Name:="INFORMATION_SCHEMA.ROUTINES")> _
Partial Public Class Routine
    Inherits Linq2SQL

    Private _SPECIFIC_CATALOG As String
    Private _SPECIFIC_SCHEMA As String
    Private _SPECIFIC_NAME As String
    Private _ROUTINE_CATALOG As String
    Private _ROUTINE_SCHEMA As String
    Private _ROUTINE_NAME As String
    Private _ROUTINE_TYPE As String
    Private _ROUTINE_BODY As String
    Private _ROUTINE_DEFINITION As String
    Private _DATATYPE As String
    Private _CHARMAXLEN As Nullable(Of Integer)
    Private _CREATED As DateTime
    Private _LAST_ALTERED As DateTime

    Public Sub New()
        MyBase.New()
    End Sub

    <Column(Name:="SPECIFIC_CATALOG", Storage:="_SPECIFIC_CATALOG")> _
    Public Property specificcatalog() As String
        Get
            Return _SPECIFIC_CATALOG
        End Get
        Set(ByVal value As String)
            _SPECIFIC_CATALOG = value
        End Set
    End Property

    <Column(Name:="SPECIFIC_SCHEMA", Storage:="_SPECIFIC_SCHEMA")> _
    Public Property specificschema() As String
        Get
            Return _SPECIFIC_SCHEMA
        End Get
        Set(ByVal value As String)
            _SPECIFIC_SCHEMA = value
        End Set
    End Property

    <Column(Name:="SPECIFIC_NAME", Storage:="_SPECIFIC_NAME")> _
    Public Property specificname() As String
        Get
            Return _SPECIFIC_NAME
        End Get
        Set(ByVal value As String)
            _SPECIFIC_NAME = value
        End Set
    End Property

    <Column(Name:="ROUTINE_CATALOG", Storage:="_ROUTINE_CATALOG")> _
    Public Property routinecatalog() As String
        Get
            Return _ROUTINE_CATALOG
        End Get
        Set(ByVal value As String)
            _ROUTINE_CATALOG = value
        End Set
    End Property

    <Column(Name:="ROUTINE_SCHEMA", Storage:="_ROUTINE_SCHEMA")> _
    Public Property routineschema() As String
        Get
            Return _ROUTINE_SCHEMA
        End Get
        Set(ByVal value As String)
            _ROUTINE_SCHEMA = value
        End Set
    End Property

    <Column(Name:="ROUTINE_NAME", Storage:="_ROUTINE_NAME")> _
    Public Property routinename() As String
        Get
            Return _ROUTINE_NAME
        End Get
        Set(ByVal value As String)
            _ROUTINE_NAME = value
        End Set
    End Property

    <Column(Name:="ROUTINE_TYPE", Storage:="_ROUTINE_TYPE")> _
    Public Property routinetype() As String
        Get
            Return _ROUTINE_TYPE
        End Get
        Set(ByVal value As String)
            _ROUTINE_TYPE = value
        End Set
    End Property

    <Column(Name:="ROUTINE_BODY", Storage:="_ROUTINE_BODY")> _
    Public Property routinebody() As Integer
        Get
            Return _ROUTINE_BODY
        End Get
        Set(ByVal value As Integer)
            _ROUTINE_BODY = value
        End Set
    End Property

    <Column(Name:="ROUTINE_DEFINITION", Storage:="_ROUTINE_DEFINITION")> _
    Public Property routinedefinition() As String
        Get
            Return _ROUTINE_DEFINITION
        End Get
        Set(ByVal value As String)
            _ROUTINE_DEFINITION = value
        End Set
    End Property

    <Column(Name:="DATA_TYPE", Storage:="_DATATYPE")> _
    Public Property datatype() As String
        Get
            Return _DATATYPE
        End Get
        Set(ByVal value As String)
            _DATATYPE = value
        End Set
    End Property

    <Column(Name:="CHARACTER_MAXIMUM_LENGTH", CanBeNull:=True, Storage:="_CHARMAXLEN", DbType:="Int")> _
    Public Property charmaxlen() As Nullable(Of Integer)
        Get
            Return _CHARMAXLEN
        End Get
        Set(ByVal value As Nullable(Of Integer))
            _CHARMAXLEN = value
        End Set
    End Property

    <Column(Name:="CREATED", CanBeNull:=True, Storage:="_CREATED")> _
    Public Property created() As DateTime
        Get
            Return _CREATED
        End Get
        Set(ByVal value As DateTime)
            _CREATED = value
        End Set
    End Property

    <Column(Name:="LAST_ALTERED", CanBeNull:=True, Storage:="_LAST_ALTERED")> _
    Public Property lastaltered() As DateTime
        Get
            Return _LAST_ALTERED
        End Get
        Set(ByVal value As DateTime)
            _LAST_ALTERED = value
        End Set
    End Property

End Class
4

0 に答える 0