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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:16:42+00:00 2026-06-07T06:16:42+00:00

I have an SQL Server Express 2012 with the following event model in the

  • 0

I have an SQL Server Express 2012 with the following event model in the Entity Framework:

eventPage: ID, name, description ..
eventDates: IDEvent, DateStart, DateEnd ..
eventTopics: IDEvent IDTopic ..
topics: ID, name, description..

So eventDates has an eventPage property and eventPage has an IEnumerable and eventTopic has a topic property and so on.

I want to make a query throuth the model and the result map it to my custom classes in C#.
I dont want to use the model classes generated by the EF, i have some classes with the only properties i need. ie:

Topic: ID, Name
EventDate: DateStart, DateEnd
Event: ID, Name, Topics, Start, End

Being Topics a List of Topic and Dates a List of EventDates

I have a method that makes the query and returns a IQueryable and from it i want a List.

So the way i get it is:

var events=GetEvents(start, end);
var eventsList = (from ev in events
                  select new {event = ev, eventPage = ev.eventPage,topics=ev.eventTopics)).ToList();
//Mapping
var map = (from ev in eventsList
select new Event(ev.event,ev.eventPage,ev.topics)).ToList();

And in the constructor i set the properties:

this.name=eventPage.Name;
this.start=event.Start;
this.end=event.End;
this.topics = topics.Select(t=>t.Topic).ToList();

But this is a bit slow for a large number of events, i would like to know if there is a more optimus way.

At the beginning the constructor only parameter was the event and inside i got the event.eventPage.Name , etc but it was too slow so i get the data i need first and after it i call the constructor.

  • 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-06-07T06:16:44+00:00Added an answer on June 7, 2026 at 6:16 am

    AutoMapper is your friend in such situation.

    I suggest you read the Getting Started guide. It’s pretty simple to understand and you’ll be able to map from your query to your custom DTOs really fast.

    Here’s the full Wiki guide. See Lists and Arrays.

    In your case it’d be something like this:

    Mapper.CreateMap<Event, MyCustomEvent>();
    
    var events =
        Mapper.Map<IEnumerable<Event>, IEnumerable<MyCustomEvent>>(Database.Events).
        AsQueryable();
    

    AutoMapper also allows you to do something like this:

    Mapper.CreateMap<Event, MyCustomEvent>().
    ForMember(dest => dest.SomeCollectionProperty, opt => opt.MapFrom(src => src.RelationshipProperty.SomeCollectionProperty));
    

    It’s really powerful! Entity Framework for example let’s you lazy load related entities by default and so I think the examples above work out of the box with a single query to the database to get the root object.

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

Sidebar

Related Questions

Using SQL Server 2012 Express. I have a table which represents key/value pairs. keycol
I have downloaded the sample database for SQL Server 2012 Express but I am
I have SQL Server Express and Visual Studio Web Developer Express running on my
I have Microsoft SQL Server Express Edition with Advanced Services for 2008. I only
I have an SQL Server 2008 Express Edition and added an Oracle DB as
I have upgraded a SQL Server Express 2005 instance to Standard using the best
SQL Server Express does not have the Tasks -> Import Data option that other
I have just downloaded SQL Server 2005 express edition from here: To be used
I have installed SQL Server 2008 R2 Express on Windows 7. When I run
It is possible in SQL Server Express have a log of all operations SELECT

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.