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 7037711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:34:41+00:00 2026-05-28T01:34:41+00:00

I am trying to map a class from SQL to a linq collection, But

  • 0

I am trying to map a class from SQL to a linq collection, But I fail..

I have got this class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace SportsStore.Entities
{
    [Table(Name = "Products")]
    public class Product 
    {
        [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
        public int ProductID { get; set; }

        [Column]public string Name { get; set; }
        [Column]public string Description { get; set; }
        [Column]public `int` Price { get; set; } 
        [Column]public string Category { get; set; }

    }
}

I call that class from another class:

using SportsStore.Abstract;
using SportsStore.Entities;
using System.Data.Linq;
using System.Linq;

    namespace SportsStore.Concrete
    {
        public class SqlProductsRepository : IProductRepository
        {
            private Table<Product> productsTable;

            public SqlProductsRepository(string connnectionString)
            {
                productsTable = (new DataContext(connnectionString)).GetTable<Product>();
            }

            public IQueryable<Product> Products
            {
                get { return productsTable; }
            }
        }

    }

Basically, I get this:

base {System.SystemException} = {“Specified cast is not valid.”}

This implies the cast is invalid

update
My database looks like that:

>

 **ProductID  int (primary key) Name  
     nvarchar(100) Description  
 nvarchar(500) Category  
 nvarchar(50) Price  int**

StackTrace:

[InvalidCastException: Specified cast is not valid.]
System.Data.SqlClient.SqlBuffer.get_Decimal() +274
System.Data.SqlClient.SqlDataReader.GetDecimal(Int32 i) +44
Read_Product(ObjectMaterializer1 ) +1088
System.Data.Linq.SqlClient.ObjectReader
2.MoveNext() +32
System.Collections.Generic.List1..ctor(IEnumerable1 collection) +406
System.Linq.Enumerable.ToList(IEnumerable1 source) +58
SportsStore.Controllers.ProductController.List() in
D:\Call.of.Duty.Modern.Warfare.3-RELOADED\SportsStore\SportsStore\SportsStore\Controllers\ProductController.cs:28
lambda_method(Closure , ControllerBase , Object[] ) +96
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase
controller, Object[] parameters) +51
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext
controllerContext, IDictionary
2 parameters) +409
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
controllerContext, ActionDescriptor actionDescriptor, IDictionary2
parameters) +52
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
+127 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
filter, ActionExecutingContext preContext, Func
1 continuation) +436
System.Web.Mvc.<>c_DisplayClassf.b_c()
+61 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext
controllerContext, IList1 filters, ActionDescriptor actionDescriptor,
IDictionary
2 parameters) +305
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
controllerContext, String actionName) +830
System.Web.Mvc.Controller.ExecuteCore() +136
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
+111 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext
requestContext) +39
System.Web.Mvc.<>c_DisplayClass8.b_4() +65
System.Web.Mvc.Async.<>c_DisplayClass1.b_0() +44
System.Web.Mvc.Async.<>c__DisplayClass81.<BeginSynchronous>b__7(IAsyncResult
_) +42 System.Web.Mvc.Async.WrappedAsyncResult
1.End() +141 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,
Object tag) +54
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,
Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
+52 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult
result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+8966925 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

  • 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-28T01:34:42+00:00Added an answer on May 28, 2026 at 1:34 am

    Your error message states that the value for the Price column cannot be converted to a decimal.

    You need to make sure that your database table has the correct column type for the Price column and that it contains valid data.

    Also, if your column in the database allows NULL values, you need to map it to a nullable decimal with decimal? Price { get; set; }

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

Sidebar

Related Questions

I'm trying to implement an identity map using generics. I have an abstract class,
Trying to map the following schema using the Entity Framework. A Customer can have
Using Sharp Architecture 1.9 I have a base class that inherits from the Sharp
I'm trying to map a struct definition using ctypes: struct attrl { struct attrl
I am trying to map several tables using Fluent Nhibernate. My tests are giving
I'm trying to map a Dictionary containing Lists. I have the following set of
I am trying to map a table frp, a SQL Server 2005 DB to
I'm unit testing a method which uses automapper to map a class from my
I'm trying to map an interface and concrete class with fluentnhibernate. here's my interface
hey guys, say I have Entities and mappings like this: public class Episode {

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.