Donc j'essaie de contourner le manque de support de procédure stockée dans mon application de reporting Silverlight et j'ai un peu de mal avec mon linq.problème de requête de framework/linq entité
J'ai une procédure stockée qui ressemble à ceci:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Some Dev Guy
-- Create date: 11/02/10
-- =============================================
Alter PROCEDURE spGetTopReferers
@p_sitekey SmallInt,
@p_startDate SmallDateTime,
@p_endDate SmallDateTime
AS
BEGIN
SET NOCOUNT ON;
SELECT
TOP 10
SUM(DaySummaryReferrers.Visits) AS Visits,
SUM(DaySummaryReferrers.NewVisitors) AS 'New Visitors',
SUM(DaySummaryReferrers.Prospects) AS Prospects,
SUM(DaySummaryReferrers.Customers) AS Customers,
Referrers.Referrer
FROM
DaySummaryReferrers
LEFT OUTER JOIN
Referrers
ON
DaySummaryReferrers.ReferrerID = Referrers.ReferrerID
Where
DaySummaryReferrers.SiteKey = @p_sitekey
AND
DaySummaryReferrers.Dated
Between
@p_startDate
AND
@p_endDate
GROUP BY
Referrers.Referrer
ORDER BY
Visits DESC;
END
GO
J'ai créé la classe DomainService suivante afin que je puisse interroger ce jour en utilisant Entity Framework. Je veux pousser le résultat de ma requête dans ma structure de données personnalisées becuase Je n'ai pas une entité qui a toutes les informations dont j'ai besoin pour mon rapport (visites spécifiquement et referrer)
namespace Reports.Web.Services
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using System.Data;
using System.Data.Objects;
public class TopReferers
{
[Key]
[Editable(false)]
public int reffererID { get; set; }
public int? Visits { get; set; }
public int? Visitors { get; set; }
public int? Prospects { get; set; }
public int? Customer { get; set; }
public String Referrer { get; set; }
}
[EnableClientAccess()]
public class WebReportAggregateService : DomainService
{
WhosOnV5DevEntities ctx = new WhosOnV5DevEntities();
public IQueryable<TopReferers> GetTopReferrers()
{
DateTime p_start = new DateTime(2010, 01, 01);
DateTime p_end = new DateTime(2010, 11, 01);
ObjectSet<DaySummaryReferrer> myReferrers = ctx.DaySummaryReferrers;
ObjectSet<Referrer> myReferrerNames = ctx.Referrers;
IQueryable<TopReferers> x = from referrer in myReferrers.Take(10)
join referrerName in myReferrerNames
on referrer.ReferrerID
equals referrerName.ReferrerID
where
referrer.SiteKey == 74
&&
referrer.Dated >= p_start
&&
referrer.Dated <= p_end
group referrer by referrerName.Referrer1 into g
select new TopReferers { Visits = g.Key.Visits, Customer = g.Key.Customers, Prospects = g.Key.Prospects, Visitors = g.Key.NewVisitors, Referrer = g.Key.Referrer, reffererID = g.Key.ReferrerID };
return x;
}
}
}
C'est là que je reçois des erreurs :
select new TopReferers { Visits = g.Key.Visits, Customer = g.Key.Customers, Prospects = g.Key.Prospects, Visitors = g.Key.NewVisitors, Referrer = g.Key.Referrer, reffererID = g.Key.ReferrerID };
erreurs:
Error 2 'string' does not contain a definition for 'Customers' and no extension method 'Customers' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) C:\Users\User\documents\visual studio 2010\Projects\Reports\Reports.Web\Services\WebReportAggregateService.cs 53 108 Reports.Web
Je reçois cette erreur de visites, personnalisée, perspectives, visiteurs, référenceur et ID de parrainage.
Toute aide serait grandement appréciée = D
Vous pouvez commencer par y compris en fait une erreur dans votre question ... –