Inject TableName as Parameter for Update & Insert on GenericEntity in ServiceStack Ormlite -


I have 3 tables of the same structure, so I have created the following unit using the service stack < Pre> public class generic entities {[alias ("COL_A")] public string column {received; Set; }}

To retrieve the results, I use the following code's code. In this I give a table name like "table" / "tablebie" so that I can get the appropriate results.

  db.Select & lt; GenericEntity & gt; (W = & gt; w.Where Where (Experian). Orders (O = & gt; O. Column A). ("Table A"););   

I use the following code to delete

  db.Delete & lt; GenericEntity & gt; (W = & gt; w.Where (q = & gt; q.ColumnA == "A") ("Table A");); With   

() I can say SELECT & amp; What is the DELETE operation in such a way to insert and update? I am using Snippet code below to update and enter

Enter
  db.Insert (New GenericEntity () {});   

update
  db.Update & lt; Generic Antity & gt; (New GenericEntity {ColumnA = "ModifiedData"}, p = & gt; p.ColumnA == "Basic Data");    

As you want it for multiple APIs on how I get it shown To do this:

  var tableName = "By clicking TableA, the OrmLite API enhances its own custom extension methods to enhance the desired behavior, which modifies OrmLite's table metadata at runtime. "'Db.DropAndCreateTable & lt; GenericEntity & gt; (TableName); Db.Insert (tagname, new GenericEntity {id = 1, column A = "A"}); Var Rows = DB Select & gt; Generic Antity & gt; (Tagname, q = & gt; q.Where (x => x.ColumnA == "A")); Rows.PrintDump (); Db.Update (tagname, new GenericEntity {ColumnA = "B"}, where: q = & gt; q.ColumnA == "A"); Line = db Select & gt; Generic Antity & gt; (Tagname, q = & gt; q.Where (x = & gt; x.ColumnA == "B")); Rows.PrintDump ();   

With these extension methods:

  Public Static Class GenericTable Extension {Static Object ExecWithAlias ​​& lt; T & gt; (String table, funk & lt; object & gt; fn) {var model DEF = typef (t) .GetModelMetadata (); Lock (modeldiff) {var catch = modeldiff.lays; Try {modelDef.Alias ​​= table; Return FN (); } Finally {modelDef.Alias ​​= catch; }}} Public Static Zero Drop Endrable & lt; T & gt; (This IDbConnection DB, string table) {ExecWithAlias ​​& lt; T & gt; (Table, () = & gt; {db.DropAndCreateTable & lt; T & gt; (); return tap;}); } Insert long lasting public & lt; T & gt; (This IDbConnection DB, string table, T OBJ, Bull Select Identity = false) {Return (Long) ExecWithAlias ​​& lt; T & gt; (Table, () => db.Insert (obj, selectIdentity)); } Public static list & lt; T & gt; & Lt; T & gt; (The IDbConnection DB, String Table, Function & lt; SqlExpression & lt; T & gt ;, SqlExpression & lt; T & gt; & gt; Expression) {Return (List & lt; T & gt;) ExecWithAlias ​​& Lt; T & gt; (Table, () => db.Select (expression); } Public static int update & lt; T & gt; (This IDbConnection db, string table, t item, expression & lt; Func & lt; t, bool & gt; & gt; where) {return (int) ExecWithAlias ​​& lt; T & gt; (Table, () = & gt; db update (item, ou)); }}   

Adding your extension methods in this way allows you to expand your Ormalai with your own idiom that is embedded in ORMLET itself. Net code IDB connection .

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -