Linq query with forward mapped classes

4 posts, 0 answers
  1. Andreas Gräfe
    Andreas Gräfe avatar
    1 posts
    Member since:
    Aug 2009

    Posted 03 Sep 2009 Link to this post

    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
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 03 Sep 2009 Link to this post

    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.
  3. DevCraft banner
  4. Sean Lynch
    Sean Lynch avatar
    1 posts
    Member since:
    Jul 2009

    Posted 12 Jan 2010 Link to this post

    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.
  5. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 13 Jan 2010 Link to this post

    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.
Back to Top