1
我得到一些樹,但 根的EF查詢:的EntityFramework:檢查整數關係是空
SomeTree.Where(t => t.ParentID == null);
或動態LINQ查詢:
SomeTree.Where("ParentID== null");
返回sql
查詢:
SELECT
CAST(NULL AS int) AS [C1],
CAST(NULL AS int) AS [C2],
CAST(NULL AS varchar(1)) AS [C3]
FROM (SELECT 1 AS X) AS [SingleRowTable1]
WHERE 1 = 0
爲什麼它不返回根?
映射:
HasKey(c => c.ID);
Property(c => c.ID).HasColumnName("ACTID").HasColumnType("int").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).IsRequired();
Property(c => c.Title).HasColumnName("ACTName").HasColumnType("nvarchar").HasMaxLength(100).IsUnicode(true).IsVariableLength().IsRequired();
Property(c => c.ParentID).HasColumnName("ACTActKindID").HasColumnType("int").IsOptional();
HasMany(c => c.Children).WithRequired(c => c.Parent).HasForeignKey(c => c.ParentID);
它可空你的parentID列,但問題是映射 – Mohsen 2012-07-21 09:00:26