This question is locked. New answers and comments are not allowed.
Hey guys,
Here is my sample DB script:
| CREATE TABLE Person |
| ( |
| Id UNIQUEIDENTIFIER NOT NULL PRIMARY KEY, |
| FirstName NVARCHAR(50) NOT NULL, |
| LastName NVARCHAR(50) NOT NULL, |
| BirthDate DATETIME2(7) NOT NULL, |
| PhoneNumber NVARCHAR(20) NULL, |
| ) |
| GO |
| INSERT INTO Person VALUES (NEWID(), 'John', 'Johnson', '1980-01-01', '+49 000 000 1000') |
| GO |
| INSERT INTO Person VALUES (NEWID(), 'Jack', 'Jackson', '1980-02-02', '+49 000 000 2000') |
| GO |
| INSERT INTO Person VALUES (NEWID(), 'Bill', 'just Bill', '1980-04-04', '+49 000 000 4000') |
| GO |
| INSERT INTO Person VALUES (NEWID(), 'No', 'Name', '1960-04-04', '+49 000 000 4000') |
| GO |
And here is my sample:
| public interface IPerson |
| { |
| string FirstName { get; set; } |
| string LastName { get; set; } |
| DateTime BirthDate { get; set; } |
| string PhoneNumber { get; set; } |
| } |
| partial class Person : IPerson |
| { |
| public override string ToString() |
| { |
| return string.Format("Person {{ {0}, {1}, {2}, {3} }}", FirstName, LastName, PhoneNumber, BirthDate); |
| } |
| static void Main() |
| { |
| // foreach (var person in GetPeople<Person>().Where(x => x.BirthDate.Year > 1970)) |
| // Console.WriteLine(person); |
| foreach (var person in GetPeople<IPerson>().Where(x => x.BirthDate.Year > 1970)) |
| Console.WriteLine(person); |
| } |
| static IQueryable<T> GetPeople<T>() where T : IPerson { return new TestEntityDiagrams().People as IQueryable<T>; } |
| } |
First of all, you guys rocks! It is absolutely cool that you generating name 'People' for person queryable collection.
Now back to my problem. If I uncomment the commented foreach, everything will work as expected. But, if the code remains commented out, an exception will be produced:
Unhandled Exception: System.InvalidOperationException: An exception occured during the execution of 'Extent<Sample.Person>.Where(x => (x.BirthDate.Year > 1970))'. See InnerException for more details.
---> System.ArgumentOutOfRangeException: Parameter expression has unexpected type.
Parameter name: x
Actual value was Sample.IPerson.
at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Typetype, Int32 elementAt, Object[] groupResolutionParamValues)
at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues)
--- End of inner exception stack trace ---
at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues)
at Telerik.OpenAccess.Query.ExpressionExecution.PerformDatabaseQuery[T](Piece`1 piece, Object[] grpVals)
Please advice.
Thanks,
Ivan.