c# - EntityFramework Linq To Entities 位域/ bool 问题

标签 c# entity-framework linq-to-entities

我对为什么会发生以下情况感到困惑:

场景是在 Stcoxrefs(它是一个纯实体而不是派生版本)中有两个位字段。

使用以下 int、char、varchar 字段是正确的,但无论数据库中有什么,位字段始终为 false,尽管在 linqpad 中运行查询可以正常工作:

public List<Stcoxref> GetAllowedStockholderTransferOrganisations(int currentStockHolder)
{
    return (from s in Entities.Stcoxrefs
            where s.OrganisationId == currentStockHolder
            orderby s.CompanyName2
            select s).ToList();
}

表映射是正确的,下面将证明...

使用以下函数所有字段都是正确的,位字段不再总是假的并且根据数据库中的数据设置。

public List<Stcoxref> GetAllowedStockholderTransferOrganisations(int currentStockHolder)
{

    List<Stcoxref> test1 = (from s in Entities.Stcoxrefs
                            where s.OrganisationId == currentStockHolder
                            orderby s.CompanyName2
                            select s).ToList();

    return test1;
}

啊?!?!?!?

编辑:Stcoxref 是一个 EntityType,这里是验证的表映射:

STCOXREF_NO : int           ->    StcoxrefNo : Int32
ROLE_CODE : char            ->    RoleCode : String
ORG_ID : int                ->    OrganisationId : Int32
ROLE_CODE2 : char           ->    RoleCode2 : String
ORG_ID2 : int               ->    OrganisationId2 : Int32
COMPANY_NAME2 : varchar     ->    CompanyName2 : String
INACTIVE : bit              ->    InActive : Boolean
SUPRESS_EMAIL : bit         ->    SuppressEmail : Boolean

InActive 和 SuppressEmail 都表现出奇怪的行为。

最佳答案

把这个作为一个答案,因为它有点像一个答案,但也因此这个问题不会添加到 SO 上不断增长的未回答问题列表中。

Gah 感谢您的帮助/时间!经过进一步测试,似乎以前的开发人员共享了上下文!呜呜……

因此,在工作单元内执行功能会按预期工作。共享上下文一定一直在搞砸位域。

更奇怪的是变量的行为使事情正常进行?!

关于c# - EntityFramework Linq To Entities 位域/ bool 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16317443/

相关文章:

c# - VisualStateManager 似乎无法在 UserControl 的 ControlTemplate 中工作

c# - Entity Framework 中 LINQ 投影的可重用计算(代码优先)

.net - Entity Framework : Can't use "Contains" with property on another object

c# - Intellisense 停止为 Linq to Entities 工作

c# - 如何使用每个 C# 智能技术将项目从其他列表添加到列表中

c# - Action<T> 为变量赋值

c# - 许多输入参数的初学者问题

c# - 在内存中使用 SQLite 运行 EF Core - 未配置数据库提供程序

c# - 带 GroupBy 的 Linq 表达式

entity-framework - 代码中是否有可以代替 fixture.Inject() 的 Autofixture 属性?