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

  • Home
  • SEARCH
  • 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 6198095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:56:13+00:00 2026-05-24T03:56:13+00:00

I have an class public class Foo { public int UserId { get; set;

  • 0

I have an class

public class Foo
{
    public int UserId { get; set; }
}

and I’m using the code first fluent mapping to map this to the database.

Property(i => i.UserId)
            .HasColumnName("userno");

the only problem is that userno is actually a char(10) in the database. How do I go about casting or converting this type? as I currently get this error.

The ‘UserId’ property on ‘Foo’ could not be set to a ‘String’ value.
You must set this property to a non-null value of type ‘Int32’.

Thanks

  • 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-24T03:56:14+00:00Added an answer on May 24, 2026 at 3:56 am

    Entity framework doesn’t have any support for type conversion in mapping so the only valid mapped property in your scenario is:

    public class Foo
    {
        public string UserId { get; set; }
    }
    

    If you want int property as well you must do:

    public class Foo
    {
        public string UserId { get; set; }
    
        public int UserIntId 
        {
           get { return Int32.Parse(UserId); }
           set { UserId = value.ToString(); }
        }
    }
    

    And add this to your mapping:

    Ignore(i => i.UserIntId);
    

    You can play with accessibility of UserId property but be aware that accessibility also affects if your mapping actually sees the property. If it doesn’t you will not have UserId mapped at all.

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

Sidebar

Related Questions

I have this class. public class Foo { public Guid Id { get; set;
Lets say I have the following: public class MyObject { [Bindable] public var foo:int
Have a interface class abc { public: virtual int foo() = 0; ... }
I have the simple class using auto-implemented properies: Public Class foo { public foo()
Let's say I have a class: class Foo { public string Bar { get
Let's say that I have a class Foo: public class Foo { public static
For example, suppose I have a class: class Foo { public: std::string& Name() {
Is it possible to have something like the following: class C { public Foo
Suppose you have a collection of Foo classes: class Foo { public string Bar;
I have class A: public class ClassA<T> Class B derives from A: public class

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.