Click here to Skip to main content
15,886,362 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Class Library to Portable Class Library Pin
BaSs_HaXoR26-Jun-14 11:50
BaSs_HaXoR26-Jun-14 11:50 
QuestionI have a PDF Documnet that would like to extract Content from PDF and Chackbox and Radio Button types fields value. PDF file have a version 1.4(Acrobat 5.x) and may be genrated from web browser Pin
Anbuselvan_8325-Jun-14 19:49
Anbuselvan_8325-Jun-14 19:49 
QuestionC sharp windows application development Pin
Galacha Kevin25-Jun-14 1:54
Galacha 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
uglyeyes25-Jun-14 0:25 
I am getting this Unable to cast object of type error for below code

var cityState = SplitValue(citiesStates[0]);
var customers = new List<customer>()
{
new Customer()
{
CustomerId = 1,
FirstName = "bikash",
LastName = "shrestha",
Email = "bikash@hotmail.com",
Address = "482 pacific hwy",
City = "Phoenix,AZ",
State = sortedStates.Where(state => state.Abbreviation == cityState[1]).SingleOrDefault(),
Zip = 85230,
Gender = Gender.Female
},
new Customer()
{
CustomerId = 2,
FirstName = "prakash",
LastName = "shrestha",
Email = "prakash@hotmail.com",
Address = "482 pacific hwy",
City = "Phoenix,AZ",
State = sortedStates.Where(state => state.Abbreviation == cityState[1]).SingleOrDefault(),
Zip = 85231,
Gender = Gender.Male
}
};
customers.ForEach(p => context.Customers.Add(p));

var companies = new List<company>()
{
new Company()
{
CompanyId = 1,
Name = "abc",
Email = "abc@hotmail.com",
Address = "xyz street",
City = cityState[0],
State = sortedStates.Where(state => state.Abbreviation == cityState[1]).SingleOrDefault(),
Zip = 2066,
Customers = new List<customer> { customers.Single(u => u.CustomerId == 1), customers.Single(u => u.CustomerId == 2) }
}
};

companies.ForEach(p => context.Companies.Add(p)); <-- here is the error.

context.SaveChanges();

My classes
----------
public class Company
{
public int CompanyId { get; set; }
[StringLength(50)]
public string Name { get; set; }
[StringLength(200)]
public string Address { get; set; }
[StringLength(500)]
public string Email { get; set; }
[StringLength(1000)]
public string Phone { get; set; }
[StringLength(50)]
public string City { get; set; }
public State State { get; set; }
public int StateId { get; set; }
public int Zip { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public virtual ICollection<customer> Customers { get; set; }

//public Company()
//{
// Customers = new HashSet<customer>();
//}
}
public class Customer
{
public int CustomerId { get; set; }
[StringLength(50)]
public string FirstName { get; set; }
[StringLength(50)]
public string LastName { get; set; }
[StringLength(100)]
public string Email { get; set; }
[StringLength(1000)]
public string Address { get; set; }
[StringLength(50)]
public string City { get; set; }
public State State { get; set; }
public int StateId { get; set; }
public virtual ICollection<company> Companies { get; set; }
public int Zip { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public Gender Gender { get; set; }
public ICollection<order> Orders { get; set; }

// public Customer()
//{
// Companies = new HashSet<company>();
//}
}


Please help. I am trying to do DataInitialization using Code first approach and having no luck.
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
uglyeyes25-Jun-14 3:20 
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
uglyeyes25-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
uglyeyes25-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
uglyeyes25-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
SnailsWayne24-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
SnailsWayne25-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
SnailsWayne25-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
Bernhard 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
SnailsWayne25-Jun-14 21:33 
QuestionWant place code logic in class using Inno setup Pin
Ashfaque Hussain24-Jun-14 20:31
Ashfaque Hussain24-Jun-14 20:31 

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.