using entity framework code first, i've created objects store data in database. implement reactiveobject class reactiveui library in these objects, notifications whenever prorerty changes more responsive ui.
but implementing adds 3 properties, namely changed, changing , throwexceptions objects. don't think problem, when loading tables in datagrid, these column too.
is there way hide these properties? cannot manually define columns because have 1 datagrid tables, select combobox..
solution found below , here: is there way hide specific column in datagrid when autogeneratecolumns=true?
void datatable_autogeneratingcolumn(object sender, datagridautogeneratingcolumneventargs e) { list<string> removecolumns = new list<string>() { "changing", "changed", "thrownexceptions" }; if (removecolumns.contains(e.column.header.tostring())) { e.cancel = true; } }
there few ways code first. first option annotate property notmappedattribute
:
[notmapped] public bool changed { get; set; }
now, information. because inheriting base class , not have access class' properties, cannot use this. second option use fluent configuration ignore
method:
modelbuilder.entity<yourentity>().ignore(e => e.changed); modelbuilder.entity<yourentity>().ignore(e => e.changing); modelbuilder.entity<yourentity>().ignore(e => e.throwexceptions);
to access dbmodelbuilder
, override onmodelcreating
method in dbcontext
:
protected override void onmodelcreating(dbmodelbuilder modelbuilder) { // .. model configuration here }
another option create class inheriting entitytypeconfiguration<t>
:
public abstract class reactiveobjectconfiguration<tentity> : entitytypeconfiguration<tentity> tentity : reactiveobject { protected reactiveobjectconfiguration() { ignore(e => e.changed); ignore(e => e.changing); ignore(e => e.throwexceptions); } } public class yourentityconfiguration : reactiveobjectconfiguration<yourentity> { public yourentityconfiguration() { // configurations } }
advantages of method define baseline configuration of reactiveobject
, rid of definitions redundancies.
more information on fluent configuration in links above.
Comments
Post a Comment