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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:53:44+00:00 2026-05-15T14:53:44+00:00

Entity framework maps DB types to .NET types, for instance SQL Server’s BigInt is

  • 0

Entity framework maps DB types to .NET types, for instance SQL Server’s BigInt is mapped to .NET’s long.

Is it possible to create a new type and have a store type (such as BigInt or VarChar) mapped to it? If so, how?

FYI, my goal is to change the way the .NET scalar writes its value to the query, and specifically the way its default value is written (I’m trying to use SQL Server’s default keyword to solve problem such as this).

Thanks,
Asaf

Update
Found a post for EF 1 saying it can’t be done. I’m not sure it’s correct for its time, and I’m even less sure it’s relevant for EF 4.

  • 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-15T14:53:45+00:00Added an answer on May 15, 2026 at 2:53 pm

    I’m almost sure you can’t create new scalar types even in EF4.0.

    What you actually can do is to create a Complex type wrapping underlying scalar type. Complex types are supported by designer in VS2010.

    <ComplexType Name="DateTimeWrapper" >
      <Property Type="DateTime" Name="Value" Nullable="false" />
    </ComplexType>
    

    Provide any default value you want and a couple of implicit conversion operators.

    public class DateTimeWrapper
        {
            private DateTime _value = DateTime.Now;
    
            public DateTime Value
            {
                get { return _value; }
                set { _value = value; }
            }
    
            public static implicit operator DateTime(DateTimeWrapper wrapper)
            {
                if (wrapper == null) return DateTime.Now;
                return wrapper.Value;
            }
    
            public static implicit operator DateTimeWrapper(DateTime date)
            {
                return new DateTimeWrapper { Value = date };
            }
        }
    

    So every entity having complex property of DateTimeWrapper type will be correctly initialized. And you can use syntax like this: MyEntity.MyDateTimeWrapperProp = DateTime.UtcNow when creating and modifying entities.

    But in queries you’ll have to write MyEntities.Where(ent => ent.MyDateTimeWrapperProp.Value == ...).

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

Sidebar

Related Questions

From Entity Framework using ASP .NET MVC 3.0, is it possible to use a
My Entity Framework model is generated from SQL Server database. Since I need to
Entity Framework 4.0 wasn't able to create auto-incremented integer identity keys with SQL Compact
Using Entity Framework 4.1 with SQL Server 2008 R2 Express. I have a strongly
Background: Entity Framework 4, with SQL Server 2008 Problem: I have a table Order
I'm trying to store a document in SQL Server 2008 using the Entity Framework.
Do Entity Framework functions automatically escape input to protect against injection? In my SQL
Using Entity Framework, I suddenly get this strange error after publishing my asp.net mvc
Entity Framework Code First is a great framework for developing new projects. But what
In Entity Framework 4, is there any easy way to create an Entity that

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.