且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从数据库中检索复选框值。

更新时间:2022-04-08 02:25:41

复选框值未存储在数据库中。数据库存储例如布尔值或您映射到复选框的内容(如ja表示已选中或nein表示未选中,无差别表示中间状态)。所以,这个问题很难回答,取决于你,我们称之为实施策略(数据库优先,代码优先,模型优先)。但是坚持使用约定并将实体框架用于数据库映射,尤其是当使用代码优先方法时,可能会留下持久性问题,并在那里加载,到框架的魔力(你可以拥有一个很大程度上透明的持久层)。另一种方法是使用注释,流畅的api或其他一些我忘记提及的编程方式,通过手工或实体框架(或任何其他orm / odm框架)将db-module / schema映射到域对象(pocos)。深入研究持久性框架的问题(我使用实体框架来解决)并找出答案。例如,请参阅实体框架代码优先:映射到数据库中的现有表 [ ^ ]

简单来说:将可选对象的布尔属性映射到数据库中的列,让实体框架为您执行绑定,并在代码中以编程方式设置复选框状态。
checkbox values are not stored in a database. the database stores e.g. boolean values or what ever you map to a checkbox (like "ja" for checked or "nein" for unchecked and "indifferent" for intermediate state). so, this question is hard to answer and depending on your, let's call it implementation strategy (database first, code first, model first). however sticking to conventions and using the entity framework for your database mappings, esp. when using the "code first" approach, may leave the persistence concerns, and there for the loading, to the magic of the framework (you can have a largely transparent persistence layer). another approach is mapping your db-module/ schema to your domain objects (pocos) either by hand or entity framework (or any other orm/ odm framework) using either annotations, or a fluent api or some other programming manner I forgot to mention. dive deeper into the matter of persistent frameworks (I sugest using the entity framework) and find out. see for example Entity Framework Code First: Mapping to Existing Table in the Database[^]
in simple words: map a Boolean property of your selectable objects to a column in your database and let the entity framework do the binding for you and set the checkbox state programmatically in your code.