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 开发者_JAVA百科= 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
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
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.
You have to use the implementation of the interface with a parameterless constructor.
精彩评论