The Infinite Loop – Beginner's SEO, Beginner C# & JQuery Tutorials Problem. Problem Solved. Loop. – The life of a programmer

20Jun/110

C#/PHP Database Object Generator/Database Access Layer Generator

This is something i have been working on.
It is virtually a tool I use to generate c#/php classes based on a database schema.
The c#/SQL integration works well, however, I am still working to support the php/mysql generation.

It creates very simple base C# classes based on a database connection. The program includes Saving Generation profiles and reloading them at a later time. It has a recently loaded profiles list - and allows you to regenerate the DAO as many times as you like.

By using this C# Database Object Generator/Database Access Layer Creation Tool I can focus on my application development as opposed to my DAL (data access layer) development.

This piece of software is currently in beta - and I am the only beta tester! :)

If you would like the installer - you can send me an email and I can send you a copy.

Here are some screenshots and some example usage!


And example usage of the classes generated by the c# database object generator tool. Note - the class HeroBase was from the generation files.

public HeroBase GetHeroById(int id)
{

SqlConnection conn = serv.GetConnection();
try
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM hero WHERE hero_id="+id;
cmd.Connection = conn;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
HeroBase h = HeroFromReaderRow(rdr);
if (h != null)
return h;
}
}
catch (Exception ex)
{
throw new Exception("Could not load Heros " + ex.Message);
}
finally
{
conn.Close();
}
return null;
}

public HeroBase HeroFromReaderRow(SqlDataReader rdr)
{
if (rdr == null)
return null;

HeroBase h = new HeroBase();
h.HeroId = Convert.ToInt32(rdr["hero_id"]);
h.HeroName = rdr["hero_name"].ToString();
h.HeroDescription = rdr["hero_description"].ToString();
h.HeroType = rdr["hero_type"].ToString();
h.ImageFile = rdr["image_file"].ToString();
h.ModelFile = rdr["model_file"].ToString();
h.BaseAutoAttackLow = Convert.ToInt32(rdr["base_auto_attack_low"]);
h.BaseAutoAttackHigh = Convert.ToInt32(rdr["base_auto_attack_high"]);
h.BaseMovementSpeed = Convert.ToInt32(rdr["base_movement_speed"]);
h.Premium = Convert.ToBoolean(rdr["premium"]);
h.Concentration = Convert.ToInt32(rdr["concentration"]);
h.ModelRotation = Convert.ToDouble(rdr["model_rotation"]);
h.ModelScale = Convert.ToDouble(rdr["model_scale"]);
h.Active = Convert.ToBoolean(rdr["active"]);
return h;

}

The reason the classes are affixed with the 'Base' word, is because this allows for the extension of these classes. HeroBase is the database version of the class - which includes base_hp, base_energy, base_movement_speed etc etc, however, an actual hero in a game will have much more than this (hp timers, energy/mana timers, current hp, current energy) - the naming of the classes allows for you to easily extend them.

For example:

public class Hero:HeroBase(){
public Hero():base(){
CurrentHP=MaxHP;
}
public int CurrentHP{get;set;}
}

I have classes created named service.
E.g HeroService - this service has necessary methods for loading heroes from the database. This service returns objects of the Hero/HeroBase type.

All in all - it saves me a ton of time and I am glad Ive written this tool. Please comment if you have any interest in it - as I would like to gauge interest before I invest more of my time into refining it. As it sits now - it is perfect for my side project development, however, if there is enough interest - I am more than willing to improve it :)

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Slashdot
  • StumbleUpon
  • Technorati
  • Yahoo! Buzz
Filed under: General Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.