System.Data.SqlClient.SqlException: Incorrect syntax near ‘<‘. MindScapeLightSpeed Entity


 

When adding a 2e partial class for a lightspeed partial entity  class just to add extra properties i ran into this error

System.Data.SqlClient.SqlException: Incorrect syntax near '<'.

and my 2e partial class looked like this

    public partial class HotelTheme
    {
        public Theme Theme { get; set; }

        public string ThemeName { get; set; }
    }

and i only wanted to add a simple property called ThemeName, then i thought i should maybe try to make a public variable out of it like this.

    public partial class HotelTheme
    {
        public Theme Theme { get; set; }

        public string ThemeName;
    }

but then i got the error

System.Data.SqlClient.SqlException: Invalid column name 'ThemeName'.

By now i was thinking Wtf! but i did not give up.

and here is the solution to add your own properties into the 2e partial class

    public partial class HotelTheme
    {
        public Theme Theme { get; set; }

        [Transient]
        private string _themeName;
        public string ThemeName
        {
            get { return _themeName; }
            set { _themeName = value; }
        }
    }

you cannot use an automatic property, you must use the old skool way, and add the attribute Transient to yr private variable.

Use partial classes to add behaviour to generated entity classes. You can also add properties in partial classes, but if those properties introduce additional state (as opposed to being wrapper or adapter properties around the existing LightSpeed fields), be sure to mark the backing fields with the TransientAttribute so LightSpeed doesn’t try to persist them.

Never use automatic properties in a LightSpeed entity class – the C# compiler generates a backing field which doesn’t map to a database column, and you can’t get at the field to mark it transient.

Hope this helps you out to ; )

Greets JB

About johnnblade aka johnnyblade Thugnology

C# Developer 9Ja Thugnology
This entry was posted in C#, Mindscape Lightspeed and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s