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

Getting error while using LINQ

1 Answer 40 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.
Gabriel
Top achievements
Rank 1
Gabriel asked on 29 Oct 2010, 06:43 PM
Hi
I have a TestClass which defines as follows:
[Telerik.OpenAccess.Persistent(IdentityField = "_id")]
    public class TestClass
    {
        private int _id;
        private int _parentID;
        private string _nameValue;
     
        public int ID
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
            }
        }
 
        public int ParentID
        {
            get
            {
                return _parentID;
            }
            set
            {
                _parentID = value;
            }
        }
 
        public string NameValue
        {
            get
            {
                return _nameValue;
            }
            set
            {
                _nameValue = value;
            }
        }
    }

I wanted to fetch some records from database using LINQ so i used the following code:
IObjectScope scope = ObjectScopeProvider1.ObjectScope();
 
var result = from c in scope.Extent<TestClass>()
             where c.NameValue.Matches("Test")
             select c;
objectView1.DataSource = result.ToList();

but i get this run-time error for the last line of code:
An exception occured during the execution of '
Extent<WindowsFormsApplication2.TestClass>.Where(c => c.NameValue.Matches("Test"))'. See InnerException for more details.

The strange thing is that when i omit the "where c.NameValue.Matches("Test")" line, everything works fine.

Can anybody tell me what's the problem?

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 01 Nov 2010, 07:50 PM
Hi Gabriel,

You should set the FieldAlias attribute for the NameValue property to be able to use this property in a query:

[Telerik.OpenAccess.Persistent(IdentityField = "_id")]
public class TestClass
{
    private int _id;
    private int _parentID;
    private string _nameValue;
  
    public int ID
    {
        get
        {
            return _id;
        }
        set
        {
            _id = value;
        }
    }
  
    public int ParentID
    {
        get
        {
            return _parentID;
        }
        set
        {
            _parentID = value;
        }
    }
  
    [Telerik.OpenAccess.FieldAlias("_nameValue")]
    public string NameValue
    {
        get
        {
            return _nameValue;
        }
        set
        {
            _nameValue = value;
        }
    }
}

Hope that helps.

Kind regards,
Damyan Bogoev
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
Tags
LINQ (LINQ specific questions)
Asked by
Gabriel
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or