Click here to Skip to main content
15,441,568 members
Home / Discussions / C#
   

C#

 
QuestionC sharp windows application development Pin
Galacha Kevin25-Jun-14 1:54
MemberGalacha Kevin25-Jun-14 1:54 
AnswerRe: C sharp windows application development Pin
OriginalGriff25-Jun-14 2:52
mveOriginalGriff25-Jun-14 2:52 
AnswerRe: C sharp windows application development Pin
Dave Kreskowiak25-Jun-14 3:16
mveDave Kreskowiak25-Jun-14 3:16 
GeneralRe: C sharp windows application development Pin
OriginalGriff25-Jun-14 3:18
mveOriginalGriff25-Jun-14 3:18 
AnswerRe: C sharp windows application development Pin
Gerry Schmitz25-Jun-14 9:51
mveGerry Schmitz25-Jun-14 9:51 
QuestionUnable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'. Pin
uglyeyes25-Jun-14 0:25
Memberuglyeyes25-Jun-14 0:25 
AnswerRe: Unable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'. Pin
Dave Kreskowiak25-Jun-14 3:14
mveDave Kreskowiak25-Jun-14 3:14 
GeneralRe: Unable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'. Pin
uglyeyes25-Jun-14 3:20
Memberuglyeyes25-Jun-14 3:20 
I updated the code to be below: but still getting same error

C#
Company company1 = new Company();
            company1.CompanyId = 1;
            company1.Name = "abc";
            company1.Email = "abc@hotmail.com";
            company1.Address = "xyz street";
            company1.City = cityState[0];
            company1.State = sortedStates.Where(state => state.Abbreviation == cityState[1]).SingleOrDefault();
            company1.StateId = 1;
            company1.Zip = 2066;
            company1.Phone = "949494848";
            company1.Customers = new List<Customer>();

            Customer customer1 = new Customer();
            customer1.CustomerId = 1;
            customer1.FirstName = "bikash";
            customer1.LastName = "shrestha";
            customer1.Email = "bikash@hotmail.com";
            customer1.Address = "482 pacific hwy";
            customer1.City = "Phoenix,AZ";
            customer1.State = sortedStates.Where(state => state.Abbreviation == cityState[1]).SingleOrDefault();
            customer1.StateId = 1;
            customer1.Zip = 85230;
            customer1.Gender = Gender.Female;
            customer1.Orders = new List<Order>();

            Customer customer2 = new Customer();
            customer2.CustomerId = 2;
            customer2.FirstName = "prakash";
            customer2.LastName = "shrestha";
            customer2.Email = "prakash@hotmail.com";
            customer2.Address = "482 pacific hwy";
            customer2.City = "Phoenix,AZ";
            customer2.State = sortedStates.Where(state => state.Abbreviation == cityState[1]).SingleOrDefault();
            customer2.StateId = 2;
            customer2.Zip = 85231;
            customer2.Gender = Gender.Male;
            customer2.Orders = new List<Order>();

            Order order1 = new Order();
            order1.Id = 1;
            order1.CustomerId = 1;
            order1.Product = "apple";
            order1.Date = DateTime.Today;
            order1.Price = 5;
            order1.Quantity = 1;

            Order order2 = new Order();
            order2.Id = 2;
            order2.CustomerId = 1;
            order1.Product = "apple";
            order2.Date = DateTime.Today;
            order2.Price = 5;
            order2.Quantity = 1;


            customer1.Orders.Add(order1);
            customer2.Orders.Add(order2);
            company1.Customers.Add(customer1);
            company1.Customers.Add(customer2);
            

            using (var dbCtx = new  CustomerManagerContext())
            {               
               
                dbCtx.Companies.Add(company1); <-- here i get same error now.
                //call SaveChanges
                dbCtx.SaveChanges();
            }

The error details:
Unable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'.
GeneralRe: Unable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'. Pin
Dave Kreskowiak25-Jun-14 3:22
mveDave Kreskowiak25-Jun-14 3:22 
GeneralRe: Unable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'. Pin
uglyeyes25-Jun-14 3:39
Memberuglyeyes25-Jun-14 3:39 
GeneralRe: Unable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'. Pin
Dave Kreskowiak25-Jun-14 3:51
mveDave Kreskowiak25-Jun-14 3:51 
GeneralRe: Unable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'. Pin
uglyeyes25-Jun-14 3:57
Memberuglyeyes25-Jun-14 3:57 
GeneralRe: Unable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'. Pin
Nathan Minier25-Jun-14 4:07
professionalNathan Minier25-Jun-14 4:07 
QuestionRe: Unable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'. Pin
Nathan Minier25-Jun-14 3:59
professionalNathan Minier25-Jun-14 3:59 
AnswerRe: Unable to cast object of type 'System.Collections.Generic.List`1[CustomerManager.Model.Customer]' to type 'CustomerManager.Model.Customer'. Pin
uglyeyes25-Jun-14 15:51
Memberuglyeyes25-Jun-14 15:51 
QuestionHow to extract a propertybag or complex object send from VB6 through MSMQ in C# Pin
SnailsWayne24-Jun-14 22:15
MemberSnailsWayne24-Jun-14 22:15 
AnswerRe: How to extract a propertybag or complex object send from VB6 through MSMQ in C# Pin
Dave Kreskowiak25-Jun-14 3:02
mveDave Kreskowiak25-Jun-14 3:02 
GeneralRe: How to extract a propertybag or complex object send from VB6 through MSMQ in C# Pin
SnailsWayne25-Jun-14 14:59
MemberSnailsWayne25-Jun-14 14:59 
GeneralRe: How to extract a propertybag or complex object send from VB6 through MSMQ in C# Pin
Dave Kreskowiak25-Jun-14 17:26
mveDave Kreskowiak25-Jun-14 17:26 
GeneralRe: How to extract a propertybag or complex object send from VB6 through MSMQ in C# Pin
SnailsWayne25-Jun-14 21:33
MemberSnailsWayne25-Jun-14 21:33 
AnswerRe: How to extract a propertybag or complex object send from VB6 through MSMQ in C# Pin
Bernhard Hiller25-Jun-14 20:29
MemberBernhard Hiller25-Jun-14 20:29 
GeneralRe: How to extract a propertybag or complex object send from VB6 through MSMQ in C# Pin
SnailsWayne25-Jun-14 21:33
MemberSnailsWayne25-Jun-14 21:33 
QuestionWant place code logic in class using Inno setup Pin
Ashfaque Hussain24-Jun-14 20:31
MemberAshfaque Hussain24-Jun-14 20:31 
AnswerRe: Want place code logic in class using Inno setup Pin
Pete O'Hanlon24-Jun-14 20:40
mvaPete O'Hanlon24-Jun-14 20:40 
GeneralRe: Want place code logic in class using Inno setup Pin
Ashfaque Hussain24-Jun-14 22:00
MemberAshfaque Hussain24-Jun-14 22:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.