This project is read-only.

Models from views

Mar 16, 2010 at 8:12 AM

I have created a OPF Model from a system view. When calling the GetObjectSet i'm getting the error message: "Invalid object name 'sys.objects'."

 

My model:
<Persistent("sys.objects")> _
Public Class sysobjects

    Private _name As String
    Private _object_id As Integer
    Private _principal_id As Integer
    Private _schema_id As Integer
    Private _parent_object_id As Integer
    Private _type As String
    Private _type_desc As String
    Private _create_date As DateTime
    Private _modify_date As DateTime
    Private _is_ms_shipped As Boolean
    Private _is_published As Boolean
    Private _is_schema_published As Boolean

    <Field(FieldName:="name")> _
    Public Property name() As String
        Get
            Return Me._name
        End Get
        Set(ByVal value As String)
            Me._name = value
        End Set
    End Property

    <Field(FieldName:="object_id")> _
    Public Property object_id() As Integer
        Get
            Return Me._object_id
        End Get
        Set(ByVal value As Integer)
            Me._object_id = value
        End Set
    End Property

    <Field(FieldName:="principal_id")> _
    Public Property principal_id() As Integer
        Get
            Return Me._principal_id
        End Get
        Set(ByVal value As Integer)
            Me._principal_id = value
        End Set
    End Property

    <Field(FieldName:="schema_id")> _
    Public Property schema_id() As Integer
        Get
            Return Me._schema_id
        End Get
        Set(ByVal value As Integer)
            Me._schema_id = value
        End Set
    End Property

    <Field(FieldName:="parent_object_id")> _
    Public Property parent_object_id() As Integer
        Get
            Return Me._parent_object_id
        End Get
        Set(ByVal value As Integer)
            Me._parent_object_id = value
        End Set
    End Property

    <Field(FieldName:="type")> _
    Public Property type() As String
        Get
            Return Me._type
        End Get
        Set(ByVal value As String)
            Me._type = value
        End Set
    End Property

    <Field(FieldName:="type_desc")> _
    Public Property type_desc() As String
        Get
            Return Me._type_desc
        End Get
        Set(ByVal value As String)
            Me._type_desc = value
        End Set
    End Property

    <Field(FieldName:="create_date")> _
    Public Property create_date() As DateTime
        Get
            Return Me._create_date
        End Get
        Set(ByVal value As DateTime)
            Me._create_date = value
        End Set
    End Property

    <Field(FieldName:="modify_date")> _
    Public Property modify_date() As DateTime
        Get
            Return Me._modify_date
        End Get
        Set(ByVal value As DateTime)
            Me._modify_date = value
        End Set
    End Property

    <Field(FieldName:="is_ms_shipped")> _
    Public Property is_ms_shipped() As Boolean
        Get
            Return Me._is_ms_shipped
        End Get
        Set(ByVal value As Boolean)
            Me._is_ms_shipped = value
        End Set
    End Property

    <Field(FieldName:="is_published")> _
    Public Property is_published() As Boolean
        Get
            Return Me._is_published
        End Get
        Set(ByVal value As Boolean)
            Me._is_published = value
        End Set
    End Property

    <Field(FieldName:="is_schema_published")> _
    Public Property is_schema_published() As Boolean
        Get
            Return Me._is_schema_published
        End Get
        Set(ByVal value As Boolean)
            Me._is_schema_published = value
        End Set
    End Property

End Class

My code for calling:
Dim item As ObjectSet(Of sysobjects) = Session.Current.ObjectContext.GetObjectSet(Of sysobjects)()

 

 

Mar 16, 2010 at 8:51 AM

The problem exists in MsSqlStorage.cs in Chili.Opf3.Storage.MsSql.MsSqlStorage.cs .

There are 2 functions GetValidFieldName and GetValidEntityName both wrap the passed attribute in a string with [ ] around. The problem is that the Entityname contains a dot. sys.objects becomes [sys.objects] and that is not recognized in SQL. The name should be [sys].[objects].

 

Therefor I changed the following in the 2 functions from:

 

string.Format("[{0}]", name);
To:
string.Format("[{0}]", name.Replace(".", "].["));