Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4023718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:37:59+00:00 2026-05-20T10:37:59+00:00

For example I have a list called Product and it has 3 columns, ProductName

  • 0

For example I have a list called Product and it has 3 columns, ProductName (which is the Title), ProductPrice and ProductType.

  • ProductName is a string
  • ProductPrice is a currency (double)
  • ProductType is a LookUp on ProductTypes List

Normally this is easy for me if it does not contain a LookUp column, but I dont know how to deal with look up columns when Inserting.

I had tried this one but it returns an error Specified cast is not valid.

Here is the current code

EntityList<ProductTypeItem> ProductTypes = dc.GetList<ProductTypeItem>("ProductType");

ProductItem newProduct = new ProductItem();

newProduct.Title = txtProductName.Text;
newProduct.ProductPrice = double.Parse(txtProductPrice.Text); 
newProduct.ProductType = (from a in ProductTypes where a.Title == ddProductType.SelectedItem.Text select a).FirstOrDefault();

dc.Product.InsertOnSubmit(newProduct);
dc.SubmitChanges();   

What would I do with the newProduct.ProductType as here is where the error occurs.

Please note that the ddProductType DataSource is the ProductType List and uses Title in its DataTextField and DataValueField

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:37:59+00:00Added an answer on May 20, 2026 at 10:37 am

    It works now and here is the solution

    EntityList<Item> ProductTypes = dc.GetList<Item>("ProductType");
    Item oProductType = (from a in ProductTypes where a.Title == ddProductType.SelectedItem.Text select a).FirstOrDefault();
    ProductItem newProduct = new ProductItem();
    
    newProduct.Title = txtProductName.Text;
    newProduct.ProductPrice = double.Parse(txtProductPrice.Text);
    newProduct.ProductType = (ProductTypeItem)oProductType;
    
    dc.Product.InsertOnSubmit(newProduct);
    dc.SubmitChanges();   
    

    The only thing I changed is to initialize the the Product Type as Item rather than ProductTypeItem, then cast it to ProductTypeItem now it works

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two List's which I want to check for corresponding numbers. for example
I have an List<int> which contains 1,2,4,7,9 for example. I have a range from
I have a list called 'optionlist' which may change length from day to day,
I have an Abstract class called Function which has 2 inheriting classes (actually 6,
I have a class called Order which has properties such as OrderId , OrderDate
I have an array called list, for example list = [0,1,2,3] in the HTML
I have a list of PDF [myfile.pdf] files on a folder/dir called example.com/uploaded/downloads/ I
I have a list with dictionary as elements. Each dictionary has an entry called
example, suppose I have one list which contains 45 element so from which i
Case example: I have a long list of items, and when I put my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.