2013-02-08 132 views
0

我發展與ASP.NET 4.0 Web應用程序。 我有一個數據庫SQL Server 2005,我正在使用實體框架5連接到它。實體框架5:net40

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中相同的查詢相同)的正確數量:第一個被複制好幾次,第二個相同的,等

爲什麼以這種方式工作?實體框架和數據庫視圖有什麼問題嗎?

+0

SQL Server 2005中_should_工作只是罰款與EF,但我懷疑沒有太多的精力進入,確保它的工作原理100%自[2011年結束主流支持(http://support.microsoft.com/lifecycle/search /default.aspx?sort=PN&alpha=SQL+Server+2005&Filter=FilterNO)。 –

回答

0

我認爲你的觀點是否正確配置,且當外實體框架的執行返回正確的結果?

有使用期,而不是在實體框架沒有表的問題。我將運行SQL Profiler並查看執行查詢時E.F正在執行的操作。

+0

我修好了! 問題是[Key]:我必須將其設置爲'cod_ppro'。 現在它工作!.. tnx – gorgonzola