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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:34:00+00:00 2026-05-31T21:34:00+00:00

My question is: is there a way with a DataContext/Table mapping to implement some

  • 0

My question is: is there a way with a DataContext/Table mapping to implement some custom mapping code between the database and the creation of my entity instance?

For a simple example, say that my Products entity class has property “double Length {get; set; }”

and my entity and all my existing code is expecting Length to be in Feet, but in the database Length is stored in meters so I need to do a conversion. Is there a way to register a callback or otherwise insert some code to set object.Length manually based on a DataRow or however the data is retrieved internally by L2S ?

Yes, I thought I could set “double LengthInMeters { set { Length=value*0.3048; } }” but I was hoping to avoid making duplicate properties and introducing ambiguity about which to use. What I’d like to do is register a closure with my DataContext to be called after a Product is created so that I can say:

DataContext.Entity<Product>().OnCreated( (p, row) => 
{ 
  p.Length = row["Length"] * 0.3048; 
  p.ProductCode = row["Sku"].ToString().Substring(1, 5);
 ...etc..
});
  • 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-31T21:34:01+00:00Added an answer on May 31, 2026 at 9:34 pm

    You can do it in the post creation. the .designer.cs class contains the OnCreated() Extensibility Method for your models. You can put it there. I would not do this however. It hides important logic. Place this code in your repository or some similar abstraction. I personally would probably get the model, then transfer the data to an application specific model before returning it from the repository. Then I’d convert it back when returning it to the repository. Not very speedy, but business apps dont usually require millisecond speeds where I work… maintainability is paramount instead.

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

Sidebar

Related Questions

Question Is there a way to have a method that will always run anytime
Question Is there a way to define a method only once in C# (in
Question: Is there a way to check if a given font is one of
Silly question - Is there a way to download the iPhone SDK without Xcode
Possible duplicate question: Is there a way to indefinitely pause a thread? In my
The real question: Is there a way to clear certain attributes for all components
I have a very theoretical question: Is there a way to ban the use
Question: Is there an easy way (library function) to perform a bitwise AND or
Simple question here: is there any way to convert from a jagged array to
a simple question here Is there a way to change the text click here

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.