This is a migrated thread and some comments may be shown as answers.

The member 'xxx' has no supported translation to SQL

10 Answers 199 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gerard Paratte
Top achievements
Rank 2
Gerard Paratte asked on 02 Jun 2010, 09:06 AM
Hi,
I'm trying to use telerik grid for mvc application.
I use linq2sql classes for model.

I've got a business object named Import. This import has a property Client of type Client. I can display property name of client in the grid but when I'm trying to sort the column client name it throw an exception.

The member 'xxx' has no supported translation to SQL



<%=Html.Telerik().Grid(Model).Name("importList").Columns( 
                          columns => 
                              { 
 
                                
                                  columns.Bound(o => o.Client.Name).Title("Agency"); 
                                  columns.Bound(o => o.stateId).Title("State"); 
                                  columns.Bound(o => o.GetLastStatus); 
                              }).Pageable(paging => paging.Enabled(true)) 
                          .Sortable(sorting => sorting.Enabled(true))%> 


Any help ?

10 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 Jun 2010, 10:52 AM
Hello Gerard Paratte,

We have a similar case demonstrated in this online example - > columns.Add( o => o.Customer.ContactName). How is it different than your case?

Greetings,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Michiel Peeters
Top achievements
Rank 1
answered on 02 Jun 2010, 12:38 PM
Well Gerard Paratte i do not see any problems in the code you have provided. Could you provide the full exception message? The member 'xxx' has no supported transaction to sql? Where stands the xxx for?
0
Gerard Paratte
Top achievements
Rank 2
answered on 02 Jun 2010, 12:51 PM
Thanks for you answer,
just one thing that I forgot, my client object come from a web service, so I create a property Agency in Import object using partial class.
I set that property when I get back the data from the db (I call the service and get object)
Is it a problem ?
0
Michiel Peeters
Top achievements
Rank 1
answered on 02 Jun 2010, 01:06 PM
Well i would say it shouldnt be any problem that your getting your data from the webservice and then set the data for the grid, but it speaks off a member in your class and as stated you are using linq2sql classes. That 'Import' object is that a object that you have created for your own or is it a linq2sql object? Have you already debugged your Ajax function when you are trying to sort? Is that property still filled with the client type when you do a sort? I think that the problem occurs that you are trying to take an object that has no rights to make use of the linq2sql stuff. If you want to make this work you can try the following code (this is VB.NET):

<MetaDataType(GetType(ImportMetaDatatype)> _
Partial Public Class Import
End Class

Public Class ImportMetaDataType
Private _Agency As Client
Public Property Agency() As Client
Get
    Return _Agency
End Get
Set(ByVal value as Client)
    _Agency = value
End Set
End Class

And in your method where you call your data you must then do it like this:

Public Function GetAgency() As Import
    Dim objImport As Import = new Import()
    objImport.Agency = _GetAgency()
    Return objImport
End Function

Public Function _GetAgency() As Agency
    ' Your sql call to the database for getting the agency
End Function

I hope it works and i hope i have understand your question correctly.

Kind regards,
Michiel Peeters

0
Gerard Paratte
Top achievements
Rank 2
answered on 07 Jun 2010, 01:04 PM
Ok, I will try to be clearer :
I've got linq2sql classes called Import (this come from database and is partial)
I've added a property of type BusinessUnit (Client in the last example) in the import class using partial.

public partial class Import 
    { 
        public BusinessUnit BusinessUnit { getset; } 
        public string GetLastStatus 
        { 
            get 
            { 
                if (Histories.Count > 0) 
                    return Histories.OrderByDescending(h => h.start).First().statusId; 
                return "unknown"
            } 
        } 
 
        public IEnumerable<RuleResult> Validate() 
        { 
            XElement rules = new XElement("Rules"); 
            foreach (var ruleDb in ImportRules) 
            { 
                var rule = ruleDb.BusinessRule.ruleDefinition; 
                rule.Attribute("Value").Value = ruleDb.value; 
                rules.Add(rule); 
            } 
            var engine = new RulesEngine(importId.ToString()); 
            var loader = new RulesLoader(new XElementLoader()); 
            engine.AddRagne(loader.LoadRules(rules)); 
            return engine.Run(); 
        } 
    } 

Here is the code to populate my Import object

            var imports = dbContext.Imports; 
            using(var client = new BusinessUnitFinderServiceClient()) 
            { 
                client.Open(); 
                foreach(var import in imports) 
                { 
                    import.BusinessUnit = client.GetBusinessUnit(new Guid(import.businessUnitId)); //call wcf service to get businessunit for eachimport 
                } 
            } 
            return imports; 
 


That is the code of the view (the grid)
<%=Html.Telerik().Grid(Model).Name("importList").Columns( 
                          columns => 
                              { 
 
                                  columns.Template(o => 
                                                       { 
                                                           Response.Write(Html.ActionLink("Details""Details""Import"
                                                                                          new {o.importId}, null)); 
                                                       }).Title("Details"); 
                                  columns.Bound(o => o.senderName).Title("Sender"); 
                                  columns.Bound(o => o.note); 
                                  columns.Bound(o => o.BusinessUnit.Name).Title("Agency"); 
                                  columns.Bound(o => o.stateId).Title("State"); 
                                  columns.Bound(o => o.Format.name).Title("Format"); 
                                  columns.Bound(o => o.enabled).Title("Enabled"); 
                                  columns.Bound(o => o.GetLastStatus); 
                              }).Pageable(paging => paging.Enabled(true)) 
                          .Sortable(sorting => sorting.Enabled(true))%> 
 

And here is the full error

The member 'Broker.Inbound.PreProcessor.MVC.Models.Import.BusinessUnit' has no supported translation to SQL.


Thanks for your help !


0
Atanas Korchev
Telerik team
answered on 07 Jun 2010, 02:47 PM
Hello Gerard Paratte,

Does the problem occur if you manually filter by that property?
var imports = dbContext.Imports;
using(var client = new BusinessUnitFinderServiceClient())
{
    client.Open();
    foreach(var import in imports)
    {
        import.BusinessUnit = client.GetBusinessUnit(new Guid(import.businessUnitId)); //call wcf service to get businessunit for eachimport
    }
}
return imports.Where(imp => imp.BusinessUnit.Name.Contains("A"));


All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Gerard Paratte
Top achievements
Rank 2
answered on 08 Jun 2010, 07:04 AM
Yes it does.

The member 'Broker.Inbound.PreProcessor.MVC.Models.Import.BusinessUnit' has no supported translation to SQL.


0
Accepted
Atanas Korchev
Telerik team
answered on 08 Jun 2010, 07:47 AM
Hello Gerard Paratte,

It seems that Linq To Sql cannot handle this situation - querying by a property which is not mapped from the SQL table. Could you please try using a ViewModel object which has all the required properties mapped from the Import and BusinessUnit objects? I think this would avoid this problem. Here is what I mean:

public class ImportViewModel
{
         // Has all the properties of the Import class which are shown in the grid

         BusinessUnit BusinessUnit
         {
                  get;
                  set;
         }
}

var imports = dbContext.Imports.Select(import => new ImportViewModel
{
   Name = import.Name,
   // Set the rest of the properties
});

foreach(var import in imports)
    {
        import.BusinessUnit = client.GetBusinessUnit(new Guid(import.businessUnitId)); //call wcf service to get businessunit for eachimport
    }

Then bind the grid to the ImportViewModel class.

I hope this helps,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Michiel Peeters
Top achievements
Rank 1
answered on 08 Jun 2010, 08:06 AM
Well what i think that the problem is, is that your giving a property in the partial class of import that contains a type. I think that you use the suggested implementation of Atanas or use make use of my solution that the problem will be solved :).
0
Gerard Paratte
Top achievements
Rank 2
answered on 08 Jun 2010, 09:38 AM
It works !
Thanks a lot !
Tags
Grid
Asked by
Gerard Paratte
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Michiel Peeters
Top achievements
Rank 1
Gerard Paratte
Top achievements
Rank 2
Share this question
or