我有一个班级:
public class NListingsData : ListingData, IListingData
{
private readonly IMetaDictionaryRepository _metaDictionary;
//Constructor.
public NListingsData(IMetaDictionaryRepository metaDictionary)
{
_metaDictionary = metaDictionary;
}
//Overridden function from abstract base class
public override List<Images> Photos
{
get
{
var urlFormat = _metaDictionary.GetDictionary(CommonConstants.ImagesUrlFormat, this.Key);
var imgs = new List<Images>();
for (var i = 0; i < PhotosCount; i++)
{
imgs.Add(new Images
{
Url = string.Format(urlFormat, this.MNumber, i)
});
}
return imgs;
}
set { }
}
}
metaDictionary由Autofac注入。
我正在使用Dapper执行查询,并尝试实现NListingsData。这就是我正在使用的:
string sqlQuery = GetQuery(predicates); //Select count(*) from LView; select * from lView;
//Use multiple queries
using (var multi = _db.QueryMultipleAsync(sqlQuery,
new
{
//The parameter names below have to be same as column names and same as the fields names in the function: GetListingsSqlFilterCriteria()
@BedroomsTotal = predicates.GetBedrooms(),
@BathroomsTotalInteger = predicates.GetBathrooms()
}).Result)
{
//Get count of results that match the query
totalResultsCount = multi.ReadAsync<int>().Result.Single();
//Retrieve only the pagesize number of results
var dblistings = multi.ReadAsync<NListingsData>().Result; // Error is here
}
return dblistings;
我收到错误
A parameterless default constructor or one matching signature (System.Guid ListingId, System.String MLSNumber, System.Int32 BedroomsTotal, System.Double BathroomsTotalInteger) is required for CTP.ApiModels.NListingsData materialization
我用来实现短小精悍的课程必须始终是无参数的吗?
现在,我可以创建一个简单的DataModel,然后映射到我的ViewModel。但这是唯一的方法吗?
答案 0 :(得分:-1)
在F#中,添加
@RunWith(MockitoJUnitRunner.class)
@Slf4j
public class ErrorPathUnitTest {
}
归因于您的DTO。
答案 1 :(得分:-3)
只需添加一个私有的无参数构造函数。这将由Dapper挑选。