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

Linq query with forward mapped classes

3 Answers 64 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andreas Gräfe
Top achievements
Rank 1
Andreas Gräfe asked on 03 Sep 2009, 11:39 AM
Hi, i've wrote some classes and successfully created a db with that. The problem is the query with a LINQ expression. When i use scope.Extend<Person>().First(x => x.Lastname=="Test") it works, but tells me that this is an obsolete. This uses a client-side methode to query the results. So i changed my code to scope.Extend<Person>().Where(x => x.Lastname=="Test").First(). Here is the problem. The exception message is "Identifier 'Lastname' is not a parameter or variable or field of 'OpenAccessTest.Leiter'. If 'Lastname' is a property please add the FieldAlias attribute to it. So i added the attribute to the property but nothing changed. I think that this attribute is for reverse mapping.

Is it possible to query my objects in the database and not in the application memory? Could anyone get me an example?

using Telerik.OpenAccess; 
 
namespace OpenAccessTest 
    [Persistent(IdentityField = "_identNummer")] 
    public class Person
    { 
        private int _identNummer; 
        public int IdentNummer 
        { 
            get 
            { 
                return _identNummer; 
            } 
            set 
            { 
                _identNummer = value; 
            } 
        } 
        private string _firstName; 
        public string Vorname 
        { 
            get 
            { 
                return _firstName; 
            } 
            set 
            { 
                _firstName = value; 
            } 
        } 
        private string _lastName; 
        public string LastName 
        { 
            get 
            { 
                return _lastName; 
            } 
            set 
            { 
                _lastName = value; 
            } 
        } 
 
        private string _address; 
        public string Address 
        { 
            get 
            { 
                return _address; 
            } 
            set 
            { 
                _address = value; 
            } 
        } 
    } 
 


Thanks,
Andreas

3 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 03 Sep 2009, 12:52 PM
Hi Andreas Gräfe,

The FieldAlias attribute is used to associate a property with a field. It is required for executing Linq statements because they use properties but internally OpenAccess builds SQL statements based on fields. So it needs to know which property corresponds to which field. The correct definition looks like this:
private string _lastname; 
 
[FieldAlias("_lastName")] 
public string LastName  
{  
    get  
    {  
        return _lastName;  
    }  
    set  
    {  
        _lastName = value;  
    }  
}  
Hope that helps.

Best wishes,
Alexander
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sean Lynch
Top achievements
Rank 1
answered on 12 Jan 2010, 09:18 PM
Is this something that you guys plan on cleaning up eventually?

Having to decorate all of my properties with the FieldAlias attribute in order to use LINQ is a little painful.

It would be nice at the minimum if there was a way to have OpenAccess do it for me through the wizard.
0
Jan Blessenohl
Telerik team
answered on 13 Jan 2010, 01:47 PM
Hi Sean Lynch,
We are working on a new metadata mechanism for the q1 release. We will have a better solution in the next release.

Regards,
Jan Blessenohl
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
LINQ (LINQ specific questions)
Asked by
Andreas Gräfe
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Sean Lynch
Top achievements
Rank 1
Jan Blessenohl
Telerik team
Share this question
or