I am working on an existing system and need to add a report via a stored procedure.
I just want to sort out some errors first.
In IReportingRepository.cs I have:
public interface IReportingRepository
{
IEnumerable<LastSundayDate<DateTime>> GetTradeMeKPISearches();
}
the first error is on the line above the LastSundayDate> part and says:
The non-generic type ‘TradeUK.Entities.Reporting.LastSundayDate’ cannot be used with type arguments
I have a class LastSundayDate.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TradeUK.Entities.Reporting
{
public class LastSundayDate
{
public virtual DateTime Date { get; set; }
}
}
In ReportingServies.cs I have:
public IEnumerable<LastSundayDate> GetTradeUKKPISearches()
{
return ReportingRepository.GetTradeUKKPISearches();
}
and then in ReportingRepository.cs I have:
public IEnumerable<LastSundayDate<DateTime>> GetTradeMeKPISearches()
{
try
{
using (SqlConnection conn = new SqlConnection(TradeUKModelContainer.CONNECTIONSTRING))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "[Reporting].[GetTradeMEKPISearches]";
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
List<LastSundayDate<DateTime>> results = new List<LastSundayDate<DateTime>>();
foreach (DataRow dr in dt.Rows)
{
string title = dr["Title"].ToString();
int count = Convert.ToInt32(dr["Total"]);
results.Add(new LastSundayDate<>());
}
}
}
}
}
catch (Exception ex)
{
throw new Exception("ReportingRepository GetTradeUKKPISearches: Error", ex);
}
}
why can i not have the type as DateTime?
thanks
Your class
is not generic, so you cannot use it as
LastSundayDate<DateTime>.Why don’t you write