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

Identifier is not a parameter or variable

1 Answer 172 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alex Serg
Top achievements
Rank 1
Alex Serg asked on 16 Apr 2014, 06:43 AM
I've downloaded and use Telerik Data Access Q1 2014 SP1 (2014.1.403.2). I have the model based on the Database First pattern. Database has the "Operation" table. In my project I've generated model from Database. Thats works fine! But I need to add custom property into one of the entities, like this:

public partial class Operation {
   private string statusText = "Active";
   [FieldAlias("statusText")]
   public string StatusText
   {
      get { return this.statusText; }
   }
}
This property does not need to exist into database table - it's defined and used only in .Net.
The Exception: "Identifier 'StatusText' is not a parameter or variable or field of 'Operations.DAL.Operation'. If 'StatusText' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alia"  occurs when I try to run following code:
var result = _context.GetAll<Operation>().Where(x => x.StatusText == "Active").ToList();

I tried to add Storage and FieldAlias attribute as well, but exception still occurs.

Can I have an extened property in partial class without having to exist it in the database table?

1 Answer, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 18 Apr 2014, 12:39 PM
Hi Alex,

The code which you are trying to run:
_context.GetAll<Operation>().Where(x => x.StatusText == "Active").ToList();
will be executed on two passes:

1)
GetAll<Operation>().Where(x => x.StatusText == "Active")
which is of IQueryable type and will create an SQL statement and will be executed on the server. So the statement will compare the column mapped to StatusText property to the value "Active". But in your case this column is not existing in the database and the idea of the property is to be used only in .NET and in memory operation.
2) The second pass will be to cast the returned IQueryable object to IList object in memory.

No matter what attributes you add to the property, when you try to insert it in the sql statement which will be executed on the server, the OpenAccessContext will thrown this exception.

I hope that helps.

Regards,
Boris Georgiev
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
General Discussions
Asked by
Alex Serg
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or