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

[Solved] Using interfaces instead of mapped classes

1 Answer 122 Views
Development (API, general 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.
ie
Top achievements
Rank 1
ie asked on 03 Jun 2010, 10:56 PM
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.

1 Answer, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 09 Jun 2010, 07:10 AM
Hello Ivan,

Unfortunately as of now we do not support interfaces in our designer. This though is scheduled for the 2010 Q2 release. For the time being I suggest sticking to the generated classes.

We do appreciate your input and if you have any other concerns or suggestions please share them with us. 

Have a great day,
Serge
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
Development (API, general questions)
Asked by
ie
Top achievements
Rank 1
Answers by
Serge
Telerik team
Share this question
or