To all my avid readers, I bring to you my Enterprise Framework and POCO generator. This is the next product in my suite of open cross platform apps that makes your life so much better.
The POCO generator is an open cross platform tool that can be used to generate your Complete data access entity classes in C# accompanied by matching stored procedures. This is an alternative to the Microsoft Entity Framework that is geared towards large enterprise systems where control over your data access is needed.
The POCO generator by default generates the c# classes based on the KooBoo.Framework NuGet package that implements the Enterprise Library from Microsoft in a more easier to use way. The KooBoo Framework also supports Transient Fault handling as well as cross entity transaction scopes. This means that if you get timeouts while assessing the database the framework will automatically retry and if you are using the entities within a transaction scope, you can easily chain multiple entity calls together giving you the freedom of accessing your data through a structured manner.
The KooBoo Framework gives you more than just data access, it comes will a whole suite of functions aimed at making C# MVC web applications simple and easy to write, including multi tenant support (Contact Me).
Here are some of the features that comes with the Framework, for any assistance please Contact Me:
Data Access
Accessing data with the KooBoo Framework is one of the core benefits and also the motivator behind the POCO generator (Which will do this all for you). If you look at the default generation of the POCO tool, you’ll notice a BusinessBase class that is inherited on all the classes, although you can turn it off, this helps to set up the data access globally for any entity as well as to provide the opportunity to run your entities within a transaction scope.
Setting up the SqlManager:
1 public abstract class BusinessBase 2 { 3 internal SqlDataManager sqlManager; 4 5 public BusinessBase() 6 { 7 sqlManager = new SqlDataManager("ConnectionStringName", null); 8 } 9 }
The SqlDataManager class supports two parameters as a constructor, the first will read the connection string from your web.config, the second parameter can be used to pass in the connection string manually.
Accessing Data:
1 DataTable dt = sqlManager.ExcecuteDataTable("SelectTable1Details", CommandType.StoredProcedure, new List<SqlParameter>() { 2 SQL.SQLParameter("PK", SqlDbType.Int, PK) 3 }); 4 5 if (dt.Rows.Count > 0) 6 { 7 PK = dt.GetDataCellValue(0, "PK").ToInt32(); 8 Name = dt.GetDataCellValue(0, "Name"); 9 10 }
Dealing with output parameters:
1 //Set output values 2 if (sqlManager.CurrentCommand != null) 3 { 4 if (sqlManager.CurrentCommand.Parameters["PKOut"].Value != DBNull.Value) 5 { 6 PK = (int)sqlManager.CurrentCommand.Parameters["PKOut"].Value; 7 } 8 }
Running Entities within a transaction scope:
1 Table1 t1 = new Table1(); 2 t1.sqlManager.BeginTransaction(); 3 4 try 5 { 6 t1.Name = "Insert 5"; 7 t1.InsertUpdateTable1(); 8 9 Table2 t2 = new Table2(); 10 t2.sqlManager.TransactionScope = t1.sqlManager.TransactionScope; 11 12 t2.Title = "Title insert 5"; 13 t2.InsertUpdateTable2(); 14 15 t1.sqlManager.CommitTransaction(); 16 } 17 catch(Exception ex) 18 { 19 t1.sqlManager.RollbackTransaction(); 20 }
By sharing the TransactionScope object of the first entity who initialised the transaction with the subsequent entities, you are able to chain them together in a transaction. When one call fails, the whole transaction will be rolled back.
Extension Methods
Part of the KooBoo Framework is a set of extension methods for various types that allows you to perform quick tasks without writing the code yourself.
DataTable – Select Duplicates:
1 DataTable dt = new DataTable(); 2 List<object> olist = dt.SelectDuplicates("ColumnName");
This will return a list of duplicate rows in the DataTable filtered on the column specified.
DataTable – Select Uniques:
1 DataTable dt = new DataTable(); 2 List<object> olist = dt.SelectUniques("ColumnName");
This will return a list of unique rows in the DataTable matched on the column specified
DataTable – Get row column value as string:
1 DataTable dt = new DataTable(); 2 string columnVal = dt.GetDataCellValue(0, "ColumnName");
DataTable – Add Column
1 DataTable dt = new DataTable(); 2 dt.AddColumn("My Column 2");
String – Convert string to Int32
1 string str1 = "1"; 2 int myInt = str1.ToInt32();
Int32 – Format an Int32 to 0 based value
1 int myInt = 123; 2 string formatted = myInt.FormatInt32(Functions.Int32Formatter.ZeroBased);
DateTime – Format a date into a readable string
1 DateTime myDate = DateTime.Now; 2 string formatted = myDate.FormatDate(Functions.DateFormatter.HourMin24);
DateTime – Difference between two dates
1 DateTime myDate1 = DateTime.Now; 2 DateTime myDate2 = DateTime.Now.AddMonths(30); 3 int years, months, days; 4 5 myDate1.DateDifference(myDate2, out years, out months, out days);
Imaging Functions
The imaging functions allows you to resize images from file or from a memory stream by specifying the width and height. This is ideal for creating thumbnails that are proportionally resized to fit into the dimensions specified.
1 ImagingFunctions img = new ImagingFunctions(); 2 MemoryStream stream = img.ResizeImagePreportional(blobStreamInput, 200, 322);
KooBoo.Framework NuGet package
You can add the KooBoo.Framework library to your project using the NuGet package.
1 PM> Install-Package KooBoo.Framework
https://www.nuget.org/packages/KooBoo.Framework/
KooBoo POCO Generator
The latest release of the KooBoo POCO generator can be downloaded from GitHub
https://github.com/TechnoDezi/KooBoo.Framework.POCO/
Have a look out for updated releases on both the Generator and the Framework for more features and enhancements.