我正在用ASP.NET 4.0开发一个web应用程序。我有一个SQL Server2005数据库,我正在使用Entity Framework5连接到它。
public class ArchivioClienti : DbContext
{
public ArchivioClienti()
: base("ICAMConnection")
{
}
public DbSet<ClientiProspect> clienti { get; set; }
}
[Table("pvw_clienti_prospect")]
public class ClientiProspect
{
[Key]
public string tipologia { get; set; }
public string cod_ppro { get; set; }
public string rag_soc { get; set; }
public string indirizzo { get; set; }
public string cap { get; set; }
public string citta { get; set; }
public string prov { get; set; }
public string nazione { get; set; }
public string telefono { get; set; }
public string fax { get; set; }
public string part_iva { get; set; }
public string cod_fisc { get; set; }
public string note { get; set; }
public string e_mail { get; set; }
public string cod_ppro_anag { get; set; }
public string cod_vage { get; set; }
public string cod_visp { get; set; }
public string fonte { get; set; }
public string cod_vzon { get; set; }
public decimal perc_provv { get; set; }
public string flag_stato { get; set; }
public string cod_anag { get; set; }
public string gg_chiusura { get; set; }
public DateTime? data_ins { get; set; }
public string cod_canale { get; set; }
}我正在尝试从一个表中获取数据。这不是一个真正的表,而仅仅是一个视图。当我使用LINQ加载查询时,
var result = from u in dbClienti.clienti
select u;
return result.ToList()我收到了正确数量的结果(与我在SQL Server Management studio中使用相同的查询收到的结果相同),但字段错误:第一个重复多次,第二个相同,依此类推。
为什么它会以这种方式工作?实体框架和数据库视图有什么问题吗?
发布于 2013-02-08 19:24:19
我假设您的视图配置正确,并且在实体框架之外执行时返回正确的结果?
在Entity Framework中使用视图而不是表是没有问题的。我会运行SQL Profiler,看看E.F在执行查询时在做什么。
https://stackoverflow.com/questions/14771138
复制相似问题