Using interfaces instead of mapped classes

2 posts, 0 answers
  1. ie
    ie avatar
    7 posts
    Member since:
    Feb 2007

    Posted 03 Jun 2010 Link to this post

    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 { getset; } 
            string LastName { getset; } 
            DateTime BirthDate { getset; } 
            string PhoneNumber { getset; } 
        } 
     
        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.
  2. Serge
    Admin
    Serge avatar
    375 posts

    Posted 09 Jun 2010 Link to this post

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