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

Customized EF data property throw LINQ to Entities Exception when doing a sort

5 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 03 Mar 2011, 06:14 AM
I have DB table Vehicle and I am using EF4. So I got a partial class Vehicle to map with the db table.
Vehicle is a master table. It has a detail table Fault.  1 vehicle could have many faults.

I am trying to get the count of fault associated with vehicle. So I created one customized property for Vehicle class. FaultCount.

Partial Class Vehicle
{

    public global::System.Int32 FaultCount
        {
            get
            {
                CCF20Entities ccf20Ent = new CCF20Entities();
                return ccf20Ent.Faults.Where(f => f.IsActive && f.FaultType == "Vehcile" && f.VehicleID== this.VehicleID).Count();
            }

        }

}
Everything works fine. I got the data I want and populate the grid. But when I try to sort the column, I get the exception.

"The specified type member 'FaultCount' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."

Any help?

Thx,
David

5 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 03 Mar 2011, 10:12 AM
Hi David,

Unfortunately, this functionality is not supported by the current version of EF.

You will have to add this property to the actual data model, i.e. calculate it in the DB, and use it like a "normal" property.

Best wishes,
Ross
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
TDG
Top achievements
Rank 1
answered on 14 Nov 2011, 08:46 PM
Does this problem supported yet?
I have many custom properties in many model class.
How do I use this model class with custom properties with MVC?

0
Kevin Hendriks
Top achievements
Rank 1
answered on 15 Nov 2011, 02:17 PM
I just got the same error in my application. I get table of which I need value and then be able to sort/group the data like so:
public partial class CUSTOMER_ORDER
    {
        public string OrderDescription
        {
            get 
            {
                if (ERPConnectionVisualEnterprise._ErpSystem != null && ERPConnectionVisualEnterprise._ErpSystem.USER_DEF_FIELDs.Any(item => item.DOCUMENT_ID.Equals(this.ID) && item.ID.Equals("UDF-0000030")))
                {
                    return ERPConnectionVisualEnterprise._ErpSystem.USER_DEF_FIELDs.Single(item => item.DOCUMENT_ID.Equals(this.ID) && item.ID.Equals("UDF-0000030")).STRING_VAL;
                }
                return "";
            }
        }    
    }

I am unable to modify the DB because it is managed by another application/company
0
Mark
Top achievements
Rank 1
answered on 07 Nov 2014, 12:34 PM
is this possible yet?
I am having the same problem.

Thanks
0
Dimitrina
Telerik team
answered on 07 Nov 2014, 03:21 PM
Hello,

As it turns out this functionality is still not supported. 

As per your request, I logged it into our system as a Feature Request. You can vote for it and follow its progress on our feedback portal here:
Add data operations support for customized EntityFramework data properties. 

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
TDG
Top achievements
Rank 1
Kevin Hendriks
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or