c# - Deploy a WPF program and update the database if required -
i'm creating wpf application uses localdb instance (which provided clickonce installer).
the program uses database store userdata. when application deployed first time, want create localdb data inserted upon initialization.
when later provide update program (which may include schema changes), not want lose any userdata.
i'm using ef code-first , dbcontext:
public class mycontext : dbcontext { public dbset<stuff> premises { get; set; } public dbset<person> persons { get; set; } private static mycontext _current; public static mycontext current { { if (_current == null) { _current = new mycontext(); } return _current; } } protected mycontext() { //some data insert on first time } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.entity<stuff>().hasmany(p => p.persons).withrequired(m => m.stuff); } }
app.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <configsections> <!-- more information on entity framework configuration, visit http://go.microsoft.com/fwlink/?linkid=237468 --> <section name="entityframework" type="system.data.entity.internal.configfile.entityframeworksection, entityframework, version=6.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" /> </configsections> <startup> <supportedruntime version="v4.0" sku=".netframework,version=v4.5" /> </startup> <connectionstrings> <add name="mycontext" connectionstring="data source=(localdb)\mssqllocaldb;integrated security=true" providername="system.data.sqlclient"/> </connectionstrings> <entityframework> <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework"> <parameters> <parameter value="mssqllocaldb" /> </parameters> </defaultconnectionfactory> <providers> <provider invariantname="system.data.sqlclient" type="system.data.entity.sqlserver.sqlproviderservices, entityframework.sqlserver" /> </providers> </entityframework> </configuration>
am correct in thinking adding development .mdf file overwrite userdata when update via clickonce?
how can let ef create schema first time, update when there's changes, , never lose userdata?
Comments
Post a Comment