您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何强制LINQ to SQL对可为空的外键执行INNER JOIN?

如何强制LINQ to SQL对可为空的外键执行INNER JOIN?

最终,我确实找到了一个很好的解决方案。答案是简单地使LINQ to sql成为可能。像这样:

using (MyDataContext context = CreateDataContext())
{
    // Set the load options for the query (these tell LINQ that the
    // Datanode object will have an associated DataObject object just
    // as before).
    context.LoadOptions = StaticLoadOptions;

    // Run a plain old sql query on our context.  LINQ will use the
    // results to populate the node object (including its DataObject
    // property, thanks to the load options).
    Datanode node = context.ExecuteQuery<Datanode>(
        "SELECT * FROM Node INNER JOIN Object " +
        "ON Node.ObjectId = Object.ObjectId " +
        "WHERE ObjectId = @p0",
        objectId).FirstOrDefault();

    //...
}
SQLServer 2022/1/1 18:53:21 有362人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶