Need to generate business entity from custom query

Anything that doesn't fall into the defect or enhancement categories

Need to generate business entity from custom query

Postby miker55 on Thu Mar 02, 2006 11:10 pm

MyGeneration is great for creating business entities from existing tables and stored procedures. However, there are many times when I need a business class for a custom query that only exists in a .sql file.

How can I get MyGeneration to retrieve field names, data types, parameters, etc. from a custom query? The database is SQL 2000.

TIA,

Mike Rodriguez
miker55
Lurker
 
Posts: 4
Joined: Thu Mar 02, 2006 11:06 pm

Postby mike.griffin on Fri Mar 03, 2006 1:04 am

Take a look at this image:

Image

This is how you should use the MyGeneration Desktop. The MyMeta browse is on the left, it is actually walking all of the MyMeta meta-data just like templates do, if you click on an item in the tree the MyMeta Properties window will show you all of the meta data properties. There is even a contact sensitive help link in the bottom right hand corner for more information.

Drill into your stored procedures and you'll see we have meta data for them.

Also, there is a template that generates code necessary to call a stored procedure for dOOdads, you could easily customize it or use it directly.
Open the Template Browser dockable window in MyGeneration and browse to:

dOOdads.C# ==> dOOdads - Invoke a Stored Procedure
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby miker55 on Fri Mar 03, 2006 3:27 am

Hi Mike,

The query I'm trying to use MyGeneration for is not a stored procedure; it's not saved on the SQL server at all. I already have over 200 stored procedures. I'm trying to avoid having to create another one every time I need a simple query.

I want to be able to just write a quick query, somehow get MyGeneration to use that to generate a business class, then delete the query after. I saw there was a LoadFromSQL method, but I'm not sure if that would help me or not.

Is something like that possible with MyGeneration?

TIA,

Mike Rodriguez
miker55
Lurker
 
Posts: 4
Joined: Thu Mar 02, 2006 11:06 pm

Postby mike.griffin on Fri Mar 03, 2006 4:19 am

Oh man, Just use the dOOdads dynamic query stuff? Have you looked at the dOOdads home page, one of the main things about dOOdads is that it eliminates the need for all those stored procs.

I'm still confused as I'm not sure what you mean mean by

The query I'm trying to use MyGeneration for is not a stored procedure;

What do you mean \"use MyGeneration for\" ?

Look at \"TheDeluxeQuery\" on this page:
http://www.mygenerationsoftware.com/por ... fault.aspx
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby miker55 on Fri Mar 03, 2006 6:04 pm

Hi Mike,

I think I'm doing a poor job of explaining this. Let me try again.

I have a typical multi-layered application, data layer, business objects, windows forms. In my windows form, I need a business object that represents a query like this:

>>>>>
SELECT h.orderdate, d.amount FROM orderheader h, orderdetail d WHERE h.ordernum = d.ordernum AND h.orderdate >= @orderdate ORDER BY h.orderdate
<<<<<

I'm trying to avoid having to create a class myself that has code like

class Orders
{
private int _orderdate;
private decimal _amount;

public int orderdate
{
get { _orderdate; }
}

public decimal amount
{
get { _amount; }
}

public Orders GetCollection
{
using (SqlConnection cn = new SqlConnection(Tools.ConnStr))
{
cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.Text;
cm.CommandText =
@\"SELECT h.orderdate, d.amount FROM orderheader h, orderdetail \" +
\"d WHERE h.ordernum = d.ordernum AND h.orderdate >= @orderdate \" +
\"ORDER BY h.orderdate \";

cm.Parameters.AddWithValue(\"@orderdate\", orderDate;

using (MyDataReader dr = new MyDataReader(cm.ExecuteReader()))
{
while (dr.Read())
{
List.Add(dr);
}
}
} // using (SqlCommand cm = cn.CreateCommand())
} // using (SqlConnection cn = new SqlConnection(Tools.ConnStr))

}

}




I know that doesn't compile, but that's basically what I'm trying to do. I want to use MyGeneration to generate a business class that contains member variables and sql statements based on a custom query.

Is that possible?

Thanks,

Mike Rodriguez
miker55
Lurker
 
Posts: 4
Joined: Thu Mar 02, 2006 11:06 pm


Return to General Questions or Comments

Who is online

Users browsing this forum: No registered users and 1 guest

cron