Print Page | Close Window

Object must implement IConvertible Error when saving inherited entities

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2203
Printed Date: 21-Jan-2026 at 1:17am


Topic: Object must implement IConvertible Error when saving inherited entities
Posted By: uwascan
Subject: Object must implement IConvertible Error when saving inherited entities
Date Posted: 30-Sep-2010 at 1:29am
I have used Inheritance in my edmx model. I get the above error when I call Save Changes. I also discovered that some of the entities make it to the db despite the error. Please how do one work with inherited entities. Sample code below.

        Administrator admin = new Administrator()
        {
            LastName = "The Name -" + DateTime.Now.Ticks.ToString(),
            FirstName = "Fast Name -" + DateTime.Now.Ticks.ToString(),
            AdminDate = DateTime.Now.Date,
        };

        Instructor teacher = new Instructor()
        {
            LastName = "De Name -" + DateTime.Now.Ticks.ToString(),
            FirstName = "La Name -" + DateTime.Now.Ticks.ToString(),
            HireDate = DateTime.Now.Date,
        };

        Student stud = new Student()
        {
            LastName = "sir Name -" + DateTime.Now.Ticks.ToString(),
            FirstName = "for Name -" + DateTime.Now.Ticks.ToString(),
            EnrolmentDate = DateTime.Now.Date,
            Degree = "Framework 101",
            Credits = 4.6
        };

        BusinessStudent bizStud = new BusinessStudent()
        {
            LastName = "As Name -" + DateTime.Now.Ticks.ToString(),
            FirstName = "Vern Name -" + DateTime.Now.Ticks.ToString(),
            EnrolmentDate = DateTime.Now.Date,
            Degree = "Entity 101",
            Descipline = "Admin",
            BusinessCredit = 5.3,
            Credits = 4.6
        };

        bizStud.EntityAspect.AddToManager();
        teacher.EntityAspect.AddToManager();
        admin.EntityAspect.AddToManager();
        stud.EntityAspect.AddToManager();

        db.SaveChanges(); //This line throws Object must implement IConvertible exception



Replies:
Posted By: sbelini
Date Posted: 05-Oct-2010 at 11:06am

uwascan,

 
Which entities get into the db and which do not?
 
Any particular difference between the classes whose entities get into the db and the classes whose entities do not?
 
Also, can you provide a test case against northwindIB, so I can verify the behavior here?


Posted By: uwascan
Date Posted: 08-Oct-2010 at 12:39am
Hi, thanks for your reply. All other entities except BusinessStudent get saved to the db.
I think DevForce does not currently support Multiple Inheritance i.e
Person ------> base object
Admin ----> inherits from Person
Instructor ----> inherits from Person
Student ----> inherits from Person
BusinessStudent ----> inherits from student

BusinessStudent  cannot be saved in this case. Entity Framewrok can handle this scenario with out problems.



Posted By: sbelini
Date Posted: 08-Oct-2010 at 10:35am
Can you upload a test case reproducing this behavior? (preferably against NorthwindIB)



Print Page | Close Window