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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:04:08+00:00 2026-05-15T02:04:08+00:00

I have a data access layer which returns an IDataRecord. I have a WCF

  • 0

I have a data access layer which returns an IDataRecord.
I have a WCF service that serves DataContracts (dto’s). These DataContracts are initiated by a parametrized constructor containing the IDataRecord as follows:

[DataContract]
public class DataContractItem
{
    [DataMember]
    public int ID;
    [DataMember]
    public string Title;

    public DataContractItem(IDataRecord record)
    {
        this.ID = Convert.ToInt32(record["ID"]);
        this.Title = record["title"].ToString();
    }
}

Unfortanately I can’t change the DAL, so I’m obliged to work with the IDataRecord as input. But in generat this works very well. The mappings are pretty simple most of the time, sometimes they are a bit more complex, but no rocket science.

However, now I’d like to be able to use generics to instantiate the different DataContracts to simplify the WCF service methods. I want to be able to do something like:

public T DoSomething<T>(IDataRecord record) {
    ...
return new T(record);
}

So I’d tried to following solutions:

  1. Use a generic typed interface with a constructor.
    doesn’t work: ofcourse we can’t define a constructor in an interface

  2. Use a static method to instantiate the DataContract and create a typed interface containing this static method.
    doesn’t work: ofcourse we can’t define a static method in an interface

  3. Use a generic typed interface containing the new() constraint
    doesn’t work: new() constraint cannot contain a parameter (the IDataRecord)

  4. Using a factory object to perform the mapping based on the DataContract Type.
    does work, but: not very clean, because I now have a switch statement with all mappings in one file.

I can’t find a real clean solution for this. Can somebody shed a light on this for me?
The project is too small for any complex mapping techniques and too large for a “switch-based” factory implementation.

  • 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-15T02:04:09+00:00Added an answer on May 15, 2026 at 2:04 am

    I think you could use AutoMapper for this. It is an open source project and it would allow to do what you want. In your do something you would do this:

    public TDestination DoSomething<TDestination>(IDataRecord record) {
       return Mapper.Map(reader, reader.GetType(), typeof(TDestination));
    }
    

    Before you can do that you would set up a map

    Mapper.CreateMap<IDataRecord, MyDestinationType>()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service, business and data access layer. In which layer should I
I have a data access layer which returns DataSets/DataTables by executing Stored Procedure. Everything
I have a repository layer that is responsible for my data-access, which is called
I have a data access layer (DAL) that is written in ASP.NET 3.5 and
I have created a Data Access Layer using .NET. Everywhere that I update a
We have a Data Access service in our SOA WCF system. This service is
I have a WCF service that uses ODP.NET to read data from an Oracle
I have a Data Access Layer library that I would like to make portable.
I have a data access layer, a business logic layer and a presentation layer
I'm writing a data access layer. It will have C# 2 and C# 3

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.