Click here to Skip to main content
15,861,168 members
Home / Discussions / C#
   

C#

 
GeneralRe: code smell ? C# public class with everything i it declared 'static Pin
Gerry Schmitz8-Feb-23 9:04
mveGerry Schmitz8-Feb-23 9:04 
AnswerRe: code smell ? C# public class with everything in it declared 'static Pin
englebart6-Mar-23 17:22
professionalenglebart6-Mar-23 17:22 
QuestionRunning MSBuild Commands from My C# console application. Pin
Madhurima Dutta7-Feb-23 4:56
Madhurima Dutta7-Feb-23 4:56 
AnswerRe: Running MSBuild Commands from My C# console application. Pin
Dave Kreskowiak7-Feb-23 5:18
mveDave Kreskowiak7-Feb-23 5:18 
AnswerRe: Running MSBuild Commands from My C# console application. Pin
jschell7-Feb-23 9:10
jschell7-Feb-23 9:10 
GeneralRe: Running MSBuild Commands from My C# console application. Pin
Madhurima Dutta8-Feb-23 4:46
Madhurima Dutta8-Feb-23 4:46 
GeneralRe: Running MSBuild Commands from My C# console application. Pin
jschell8-Feb-23 5:07
jschell8-Feb-23 5:07 
QuestionSystem.InvalidCastException: 'Unable to cast object of type 'System.Collections.Generic.List`1[FirstMVCApplication.Models.Products]' to type 'FirstMVCApplication.Models.Products'.' Pin
Member 136517316-Feb-23 21:41
Member 136517316-Feb-23 21:41 
This is Model Class
public class CartInfo
    {
        [Key]
        public int S_NO { get; set; }
        public virtual int Bill_Id { get; set; }
        public virtual int Ship_Id { get; set; }
        public virtual int Product_Id { get; set; }
        [ForeignKey("Product_Id")]
        public List<Products> Products { get; set; }
        public int Sub_Total { get; set; }
        public int Product_Quantity { get; set; }  
    }
    [Table("Product_Detail")]
    public class Products
    {
      [Key, Column(Order = 0)]
        public int Product_Id { get; set; }
         public string Product_Code { get; set; }
        public string Product_Name { get; set; }
        public int Unit_Price { get; set; }
      
    }

Insert command
string code = (model.Cart[i]).Products[0].Product_Code;
                    var _products = (from p in db.Products where p.Product_Code ==code select p).FirstOrDefault();
                    int Product_Id = _products.Product_Id;
                    CartInfo cart = new CartInfo();
                    cart.Bill_Id = Bill_Id;
                    cart.Ship_Id = Ship_Id;
                    cart.Product_Id = Product_Id;
                    cart.Products = new List<Products>();
                    var pf = new Products();
                    //pf =(from p in db.Products where p.Product_Code == code select p).FirstOrDefault();
                    pf.Product_Code = (model.Cart[i]).Products[0].Product_Code;
                    pf.Product_Name = (model.Cart[i]).Products[0].Product_Name;
                    pf.Unit_Price = (model.Cart[i]).Products[0].Unit_Price;
                    cart.Products.Add(pf);
                    cart.Product_Quantity = (model.Cart[i]).Product_Quantity;
                    cart.Sub_Total = (model.Cart[i]).Sub_Total;
                    db.Cart_Details.Add(cart);   <big>// Getting error on this line.'Unable to cast object of type 'System.Collections.Generic.List`1</big>  
                    db.SaveChanges();

AnswerRe: System.InvalidCastException: 'Unable to cast object of type 'System.Collections.Generic.List`1[FirstMVCApplication.Models.Products]' to type 'FirstMVCApplication.Models.Products'.' Pin
Eddy Vluggen7-Feb-23 1:13
professionalEddy Vluggen7-Feb-23 1:13 
AnswerRe: System.InvalidCastException: 'Unable to cast object of type 'System.Collections.Generic.List`1[FirstMVCApplication.Models.Products]' to type 'FirstMVCApplication.Models.Products'.' Pin
Gerry Schmitz7-Feb-23 13:26
mveGerry Schmitz7-Feb-23 13:26 
Questionxtendd Pin
PV20235-Feb-23 20:43
PV20235-Feb-23 20:43 
AnswerRe: xtendd Pin
OriginalGriff5-Feb-23 20:44
mveOriginalGriff5-Feb-23 20:44 
GeneralRe: xtendd Pin
PV20235-Feb-23 20:48
PV20235-Feb-23 20:48 
GeneralRe: xtendd Pin
Eddy Vluggen7-Feb-23 1:16
professionalEddy Vluggen7-Feb-23 1:16 
GeneralRe: xtendd Pin
RedDk7-Feb-23 7:05
RedDk7-Feb-23 7:05 
QuestionHow do I take datatable values into postgresql Pin
Member 141039872-Feb-23 8:22
Member 141039872-Feb-23 8:22 
AnswerRe: How do I take datatable values into postgresql Pin
Gerry Schmitz2-Feb-23 9:08
mveGerry Schmitz2-Feb-23 9:08 
GeneralRe: How do I take datatable values into postgresql Pin
jschell3-Feb-23 5:23
jschell3-Feb-23 5:23 
GeneralRe: How do I take datatable values into postgresql Pin
Gerry Schmitz3-Feb-23 7:10
mveGerry Schmitz3-Feb-23 7:10 
AnswerRe: How do I take datatable values into postgresql Pin
Dave Kreskowiak2-Feb-23 9:11
mveDave Kreskowiak2-Feb-23 9:11 
AnswerRe: How do I take datatable values into postgresql Pin
Richard MacCutchan2-Feb-23 21:40
mveRichard MacCutchan2-Feb-23 21:40 
AnswerRe: How do I take datatable values into postgresql Pin
jschell3-Feb-23 5:30
jschell3-Feb-23 5:30 
GeneralRe: How do I take datatable values into postgresql Pin
Member 141039873-Feb-23 21:33
Member 141039873-Feb-23 21:33 
GeneralRe: How do I take datatable values into postgresql Pin
Dave Kreskowiak4-Feb-23 5:40
mveDave Kreskowiak4-Feb-23 5:40 
AnswerRe: How do I take datatable values into postgresql Pin
Richard Deeming5-Feb-23 22:52
mveRichard Deeming5-Feb-23 22:52 

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.