1

我必须得到一些树的根,但是 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);
4

1 回答 1

1
WHERE 1 = 0

看起来很糟糕,(IE这永远不会回来)

我猜您数据库中的 parentID 列不可为空

于 2012-07-21T07:03:33.383 回答