Mathieu
Mathieu

Reputation: 4520

Error while using interface as a type

I'm querying a table with a SQL query (table is decided dynamically). All the tables implement the ITableIsFile interface. Here is the problematic code.

            string sql = "Select * from " + file + " where userID = '" + currAgentTM.systemuserid.Value
            + "' and CallStatusID = null";
        var records = appelsDataContext.ExecuteQuery<ITableIsFile>(sql);

On the last line, I get the following error: The type 'MRS_Admin.ITableIsFile' must declare a default (parameterless) constructer in order to be constructed during mapping.

From what I know (and have tested), it is not possible to implement a constructor in an interface.

Thank you for any help you can provide, it is much appreciated. Mathieu

Upvotes: 0

Views: 210

Answers (3)

phoog
phoog

Reputation: 43056

I think AS-CII means that you should create a base class from the interface, and use that type. For example, instead of:

interface ISomething { }

class SomethingOne : ISomething { }

class SomethingTwo : ISomething { }

try:

interface ISomething { }

class SomethingBase : ISomething { }

class SomethingOne : SomethingBase { }

class SomethingTwo : SomethingBase { }

But note the requirements in the remarks section here http://msdn.microsoft.com/en-us/library/bb361109.aspx

Upvotes: 2

asawyer
asawyer

Reputation: 17808

http://msdn.microsoft.com/en-us/library/bb361109.aspx

TResult must be a concrete class that the data context is cabable of mapping the return set to.

Upvotes: 2

as-cii
as-cii

Reputation: 13039

You have to use the implementation of the interface with a parameterless constructor.

Upvotes: 1

Related Questions