我必须得到一些树的根,但是 EF查询:
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);
答案 0 :(得分:1)
WHERE 1 = 0
看起来很糟糕,(IE不会再回来了)
我猜你的数据库中的parentID列是不可为空的