c# - In-Memory Database - How to Generate MVC Model classes? -
i new mvc4 asp.net , in-memory databases. apologize if answer basic , stupid. have created asp.net mvc application uses in-memory db(sqlite3)by using
sqliteconnection con=new sqliteconnection(data source=:memory:;version=3;new=true;);
i want know if database , tables created "in-memory", how model , classes generated can use in controller/views. in memory database populated @ runtime xml.
edit
here how create table in memory
using (sqliteconnection connection = new sqliteconnection("data source=:memory:;")) { connection.open(); connection.createmodule(new sqlitemoduleenumerable("samplemodule", new string[] { "one", "two", "three" })); using (sqlitecommand command = connection.createcommand()) { command.commandtext ="create virtual table t1 using samplemodule;"; command.executenonquery(); } using (sqlitecommand command = connection.createcommand()) { command.commandtext = "select * t1;"; using (sqlitedatareader datareader = command.executereader()) { while (datareader.read()) console.writeline(datareader[0].tostring()); } } connection.close(); }
here c# sqlite library: http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki
the low-tech way solve problem not generate model classes. create them hand correspond part of database wish work on in views. remember models meant use of view - should emphasize things controller needs pass view, , view needs pass controller. if happen mirror database structure, that's bonus.
there may more-sophisticated ways of doing things, haven't used them. it's possible create entity framework code first model, , use database migrations create in-memory tables. it's possible lazy , use exact same classes model pass views.
better have entity framework classes worry entity framework, , let model classes worry views. use tool automapper copy data between model passed view , entity framework classes passed database.
Comments
Post a Comment