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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:27:16+00:00 2026-05-12T00:27:16+00:00

I have a unique requirement that I hope is possible with LINQ to SQL.

  • 0

I have a unique requirement that I hope is possible with LINQ to SQL.

First off, I am extending an older application so I am stuck with current database column names and the existing LINQ entity classes.

I have a LINQ wrapper with the following method:

public T Get(int id) where T : class, IEntity {
  ...
}

IEntity looks like:

public interface IEntity {
  int Id { get; }
}

My existing entity class (generated by LINQ) looks like:

//this is not the exact code
//it is just to give you an idea
public parital class Widget {
  public int WidgetId { get; set; }
  public string WidgetName { get; set; }
}

So in order to make Widget work with my wrapper I extended it to be an IEntity like:

public partial class Widget : IEntity {
  public int Id { get { return WidgetId; } }
}

When I do a select like:

Repository<Widget>.Get(123);

I get an error saying Id is not mapped in SQL.

What I want to know is there a way for me to make Widget an IEntity and use Id as an alias of WidgetId. There is already a lot of older code written (without the repository wrapper) that references WidgetId so I don’t want to have to change this.

All suggestions are appreciated. Am I going about this wrong?

  • 1 1 Answer
  • 3 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-12T00:27:16+00:00Added an answer on May 12, 2026 at 12:27 am

    LINQ doesn’t know to translate Id to WidgetId.

    In the O/R designer you can rename the columns to whatever you need them to be. When you do this, LINQ will be able to properly translate the column names. Renaming them in the O/R designer doesn’t affect the database at all, so it is a perfectly safe operation. You can open the .designer.cs file and see how the Attributes are used to map column names to class properties.

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

Sidebar

Related Questions

Using SQL Server 2008, I have a requirement that email addresses in my user
I have to write something in vbscript that need to use a unique set.
I have a field in a database that is nearly unique: 98% of the
I have a 100 classes that have some similar elements and some unique. I've
I have a slightly unique requirement with the Java-JDBC API along with Oracle Database.
I have several tables whose only unique data is a uniqueidentifier (a Guid) column.
I have a list of about a hundreds unique strings in C++, I need
I have some data files to import into a database with some unique delimiters:
I have a situation where I need to add an arbitrary unique id to
I have a Tags table whose schema consists of only ID and Name (unique).

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.