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

C#

 
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 
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 
Ok. I did as per you mentioned but I get below error now
C#
using (var dbCtx = new CustomerManagerContext())
            {
                dbCtx.Customers.Add(customer1);
                dbCtx.SaveChanges();
                 dbCtx.Customers.Add(customer2);
                dbCtx.SaveChanges();
                dbCtx.Companies.Add(company1);
                //call SaveChanges
                dbCtx.SaveChanges();
               
                 dbCtx.Orders.Add(order1);
                 dbCtx.SaveChanges();
                dbCtx.Orders.Add(order2);
                 dbCtx.SaveChanges();
                
            }


Entities in 'CustomerManagerContext.Customers' participate in the 'Customer_Companies' relationship. 0 related 'Customer_Companies_Target' were found. 1 'Customer_Companies_Target' is expected.

this is because I have below method
C#
protected override void OnModelCreating(DbModelBuilder modelBuilder)
       {

           modelBuilder.Entity<Customer>().
           HasMany(c => c.Companies).
           WithMany(p => p.Customers).
           Map(
           m =>
           {
               m.MapLeftKey("CustomerId");
               m.MapRightKey("CompanyId");
               m.ToTable("CustomerCompany");
           });
           modelBuilder.Entity<Company>().HasRequired(c => c.Customers).WithMany().WillCascadeOnDelete(false);
           modelBuilder.Entity<Customer>().HasRequired(c => c.Companies).WithMany().WillCascadeOnDelete(false);
           base.OnModelCreating(modelBuilder);
       }


sorry still learning entity framework.
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 
AnswerRe: Want place code logic in class using Inno setup PinPopular
Pete O'Hanlon24-Jun-14 20:40
mvePete O'Hanlon24-Jun-14 20:40 
GeneralRe: Want place code logic in class using Inno setup Pin
Ashfaque Hussain24-Jun-14 22:00
Ashfaque Hussain24-Jun-14 22:00 
QuestionCreate Microsoft Excel in C# Pin
Jassim Rahma24-Jun-14 20:22
Jassim Rahma24-Jun-14 20:22 
AnswerRe: Create Microsoft Excel in C# Pin
Kornfeld Eliyahu Peter24-Jun-14 20:29
professionalKornfeld Eliyahu Peter24-Jun-14 20:29 
AnswerRe: Create Microsoft Excel in C# Pin
Richard Deeming25-Jun-14 1:32
mveRichard Deeming25-Jun-14 1:32 
SuggestionRe: Create Microsoft Excel in C# Pin
LucasRLS25-Jun-14 1:57
LucasRLS25-Jun-14 1:57 

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.