Need Help on using Generated DAL code
Need Help on using Generated DAL code
I'm sure this is a truly newbie question but I haven't implemented a Object Data Source and generated data access layers before. I've reviewed the topic viewtopic.php?f=47&t=6889&hilit=namespa ... cess+layer but for me, it assumes several things.
I've got MyGeneration installed and working and can generate the code files. But now I don't know what to do with them. I think I have to add them to the application Data Source but I'm not sure how to do that. One article pointed me towards AbleCommerce.mdf but when I try to open it, I get a message Connections to .mdf files require SQL Server Express 2005. I'm using SQL Server 2005 Developer Edition.
Can someone help me out? Thanks.
I've got MyGeneration installed and working and can generate the code files. But now I don't know what to do with them. I think I have to add them to the application Data Source but I'm not sure how to do that. One article pointed me towards AbleCommerce.mdf but when I try to open it, I get a message Connections to .mdf files require SQL Server Express 2005. I'm using SQL Server 2005 Developer Edition.
Can someone help me out? Thanks.
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: Need Help on using Generated DAL code
If you are going to use them in your store and not create a separate dll, you can put the code into a .cs file in the App_Code folder.
If you had more than one table involved, you will need to reformat the code some. There will be extra namespace and using sections with each section of code for the table involved.
If you had more than one table involved, you will need to reformat the code some. There will be extra namespace and using sections with each section of code for the table involved.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: Need Help on using Generated DAL code
Thank you for the info Judy. After generating my files, I'm wondering if I've got the right templates or if MyGeneration isn't configured right for my computer. I grabbed the templates from the first attachment in this post: viewtopic.php?f=47&t=9530&hilit=data+access+layer. In viewtopic.php?f=47&t=6889&hilit=namespa ... cess+layer, they give an example of the generated collection class as:
but my generated code came out like this:
Overall, there were several things off:
Please let me know if I've missed a step somewhere. Thanks.
Code: Select all
namespace CommerceBuilder.Marketing
{
using System;
using CommerceBuilder.Common;
/// <summary>
/// This class implements a PersistentCollection of Affiliate objects.
/// </summary>
public partial class AffiliateCollection : PersistentCollection<Affiliate>
{
/// <summary>
/// Gets the index of the CatalogNode object in this collection whose primary key
/// matches the given value.
/// </summary>
/// <param name="affiliateId">Value of AffiliateId of the required object.</param>
/// <returns>Index of the required object.</returns>
public int IndexOf(Int32 affiliateId)
{
for (int i = 0; i < this.Count; i++)
{
if (affiliateId == this[i].AffiliateId) return i;
}
return -1;
}
}
}
Code: Select all
using System;
using CommerceBuilder.Common;
namespace YourNamespace
{
public partial class ShipIntervalsCollection : PersistentCollection<ShipIntervals>
{
public int IndexOf()
{
for (int i = 0; i < this.Count; i++)
{
i ) return i;
}
return -1;
}
}
}
- no comment lines in any generated file.
- IndexOf won't compile and doesn't seem similar to the one in AffiliateCollection.Generated.cs
- the ShipIntervals default constructor is repeated twice in ShipIntervals.Generated.cs
- MyGeneration didn't create the output files automatically nor did it seem to remember the template default folder location (which I set to something other than the installation directory).
Please let me know if I've missed a step somewhere. Thanks.
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: Need Help on using Generated DAL code
You might not have had a primary key on the table. Here's one I did-- you do have to clean them up some, but it is so much faster than writing it all by hand.
Code: Select all
using System;
using CommerceBuilder.Common;
using CommerceBuilder.Data;
namespace W2MCustomClasses
{
public partial class ReferralOrdersCollection : PersistentCollection<ReferralOrders>
{
public int IndexOf(Int32 pOrderId)
{
for (int i = 0; i < this.Count; i++)
{
if( ( pOrderId == this[i].OrderId) ) return i;
}
return -1;
}
}
}
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: Need Help on using Generated DAL code
Bingo! That fixed the weird duplications and compile issues.
Should there be comments in the generated files? Do I need to customize the templates for that or add them by hand?
Also, what are the best sources of documentation for MyGeneration? Like most help, it suffers from a deficient index.
Lastly, I assume I only need to split the generated files if I need to customize the class. If the default works for me, then I'll just have three class files, correct?
Thanks.
Should there be comments in the generated files? Do I need to customize the templates for that or add them by hand?
Also, what are the best sources of documentation for MyGeneration? Like most help, it suffers from a deficient index.
Lastly, I assume I only need to split the generated files if I need to customize the class. If the default works for me, then I'll just have three class files, correct?
Thanks.
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: Need Help on using Generated DAL code
I've added comments to my generated files by hand and I've also split them up for each "object" (table). mazhar also recommended naming them something like xxxgenerated.cs. That is what Able did with their code so that they can regenerate them easily without worrying about overwriting their custom stuff they couldn't generate. For example, they have an order.cs and an ordergenerated.cs in their source code-- How cool is that?
If you add comments, you can also come up with some cool help files using Sandcastle Help File builder- see image attached.
If you add comments, you can also come up with some cool help files using Sandcastle Help File builder- see image attached.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: Need Help on using Generated DAL code
Thanks Judy.
I added a custom table which cross references vendors and ship methods. It doesn't contain a StoreId field since vendors and shipmethods do. If I want LoadForStore method(s) in my table's datasource class, I assume I have to copy and modify the LoadForCriteria method. Of course, I'll have to split the file in case of future regenerations.
Are all custom LoadForXxx methods done manually or do any templates generate that code based on foreign key fields in the underlying table?
I added a custom table which cross references vendors and ship methods. It doesn't contain a StoreId field since vendors and shipmethods do. If I want LoadForStore method(s) in my table's datasource class, I assume I have to copy and modify the LoadForCriteria method. Of course, I'll have to split the file in case of future regenerations.
Are all custom LoadForXxx methods done manually or do any templates generate that code based on foreign key fields in the underlying table?
Re: Need Help on using Generated DAL code
No currently templates do not generate load methods for foreign key references you need to write that manually.