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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:34:10+00:00 2026-05-23T17:34:10+00:00

We’re trying to implement a data layer with ORM between our domain entities and

  • 0

We’re trying to implement a data layer with ORM between our domain entities and our tables using EF. We’ve successfully done trivial mappings with domain entities that closely resemble their respective tables, but have stumbled when trying to map objects with more complex relationships that include foreign keys in their table representations. I’ve found plenty of references to “Table Splitting” using EF with tables that share primary keys, but that’s not the case with our schema.

As an example, I’d like to have domain entities as POCO’s with no more awareness of the data layer than simple ID’s:

public class EntityInfo
{
    public int EntityId { get; set; }
    public string EntityName { get; set; }
    public string TypeName { get; set; }
    public string ComponentName { get; set; }
}

public class Entity
{
    public int EntityId { get; set; }
    public EntityType Type { get; set; }
    public EntitySource Source { get; set; }
    public string Name { get; set; }
}

public class EntityType
{
    public int TypeId { get; set; }
    public string Name { get; set; }
}

public class EntitySource
{
    public int SourceId { get; set; }
    public string Name { get; set; }
}

These would be mapped to a series of equivalent tables with foreign keys:

Table Entities:
[PK]    int     EntityId
[FK]    int     TypeId
[FK]    int     SourceId
        string  Name

Table EntityTypes:
[PK]    int     TypeId
        string  Name

Table EntitySources:
[PK]    int     SourceId
        string  Name

What we’d really like to do is separate the table representation from the domain entities entirely and implement the mapping layer (.msl) to resolve these somewhat complex relationships. The EntityInfo class above would be built from and store to the tables, despite having no direct table representation of its own. Is such a mapping (multiple tables-to-object hierarchy) even possible using an .msl? Is it possible with EF?

  • 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-23T17:34:11+00:00Added an answer on May 23, 2026 at 5:34 pm

    Did you at least try it? There is no complex mapping in your presented model. That is the most basic mapping of one-to-many relationships. Simply open EDMX in the designer and run Update from database command (from context menu). Select your three tables in the wizard and uncheck option for adding foreign keys to the model.

    Edit:

    Yes entity framework is able to map even your EntityInfo object but the object will be read only because all information about what related entities (their FK relations) it includes will be lost. There are two ways to map it:

    • Use DefiningQuery in SSDL. DefiningQuery is custom SQL used to load columns you want to map. EF doesn’t bother how many tables you join to get your result set. The problem is that default designer will delete your DefiningQuery each time you try to Update model from database.
    • Use QueryView in MSL. QueryView is custom Entity SQL view mapped to a new enttiy. It is built on entities defined in your model. So you must map Entity, EntityType and EntitySource as well (but you can make them for example internal to your data assembly). QueryView survives updates from database.

    Both DefiningQuery and QueryView must be defined directly in EDMX (opened as XML) because designer doesn’t support them. These features are not available in code-first approach. These features create read only entities so if you want CUD operations as well you have to create stored procedures and map them to newly created entities.

    There is also one last option most commonly used – you can create linq-to-entities query simply projecting your mapped entities to unmapped EntityInfo:

    var infos = context.Entities
                       .Select(e => new EntityInfo
                            {
                                EntityId = e.EntityId,
                                EntityName = e.Name,
                                TypeName = e.Type.Name,
                                ComponentName = e.Source.Name 
                            });              
    
    • 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 a data compression idea I've had, and since I'm imagining
I am trying to implement a data push from a Windows Service to a
I am trying to implement a ListView data control for displaying and editing lookup
I am trying to implement a decorator chain for my data-access based on IRepository.
I've been trying to work out how to implement Church-encoded data types in Scala.
trying to implement a dialog-box style behaviour using a separate div section with all
My application data access layer is built using Spring and EclipseLink and I am
I'm trying to follow the tutorial found here to implement a service layer in
I'm working on a mobile view of our site. I'm trying to implement JQuery
I am trying to implement the MVP method for the first time, using WinForms.

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.