0
nulll在我的代碼,我一直在使用LINQ到存取權限在我的數據庫中的數據,但是有一個表,其中它一點兒也不工作。此表有幾個領域:LINQ查詢返回在不可爲空場
ID => string, not nullable
Name => string, not nullable
Date => DateTime, not nullable
UserID => string, not nullable.
當我使用的查詢,試圖得到這些數據我場的每一個返回正確的數據,除了一個:UserID
,它總是會返回null
,不管裏面有什麼。
有我的查詢:
using(ProgetEntities pg = ProgetEntities()){
List<Alloc> ListAlloc = new List<Alloc>();
ListAlloc = pg.Allocations.ToList();
}
有我的屬性的Alloc:
public partial class Alloc
{
public string ID { get; set; }
public string Name { get; set; }
public Nullable<System.DateTime> Date { get; set; }
public string UserID { get; set; }
}
我在查詢中使用AsEnumerable嘗試,但結果是一樣的。
有這樣的問題發生在任何人面前?還有其他人有一些想法,我怎麼可以嘗試解決這個問題?
編輯
通過尋找到查詢我已經找到了問題(我不知道爲什麼我did'nt考慮早點),還有的查詢(從調試器):
pg.Alloc {SELECT
[Extent1].[ID] AS [ID],
[Extent1].[NAME] AS [NAME],
[Extent1].[DATE] AS [DATE],
FROM [dbo].[Alloc] AS [Extent1]}
System.Data.Entity.DbSet<ClassGetMS.Models.Alloc>
這似乎是我的查詢不包括用戶ID字段。
'列表 ListAlloc =新列表(); ListAllocations = pg.Allocations.ToList();'你不應該把'ToList'分配給'ListAlloc'而不是'ListAllocations'?這會以任何方式幫助嗎? –
Will
當我輸入代碼時,我的糟糕的輸入錯誤,會修復srry – user3399
在你的數據庫中,你的'UserID'是什麼數據類型?它是一個int嗎? – Will