Skip to content

Method has no supported translation to SQL

June 23, 2017

I have encountered many LINQ to SQL errors recently where I have predominately been linking objects from the dbml file to the backend C# code with much experimentation. If you are translating the C# code for LINQ to SQL, you may stumble upon this error: –

Method ‘Project.Model.DrivingLicence GetDataRow(Project.Data.Objects.CheckDrivingLicence_view)’ has no supported translation to SQL.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: Method ‘Project.Model.DrivingLicence GetDataRow(Project.Data.Objects.CheckDrivingLicence_view)’ has no supported translation to SQL.

If so, then the issue is that the method you wrote, in this situation ,  the method name GetDataRow cannot be translated to the relevent SQL code even though it is configured correctly on the DBML file as I have found out.

You will often need to write an alternative method than the GetDataRow as specified: –

public static Model.GetDrivingLicence GetDataRow(Project.Data.Objects.DrivingLicences_view entity)
{
return new Model.DrivingLicence()
{
LicenceNumber = entity.LicenceNumber,
LicenceTypeId = entity.LicenceTypeID.Value,
LicenceStatusId = entity.LicenceStatusID,
InsuranceCategoryId = entity.InsuranceCategoryID.Value,
InsuranceCategory= entity.InsuranceCategory,
Active = entity.Active.Value,
Description = entity.Description,
CarType = entity.CarType,

CarModel = entity.CarModel,

CarManufacturer = entity.CarManufacturer
};

}

You will often need to write a method that reads off the database using LINQ to SQL than picking up as entity which may have an issue with the naming of the columns.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: