Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDAL 2 JoinsDAL 2 Joins
Previous
 
Next
New Post
3/11/2013 9:27 AM
 

I'm finally getting around to working with DAL 2. So far so good. Simple CRUDS are easy enough to do, and the code is down drastically for those operations. Except now I need to join to another table. Here is my example

[TableName("Jobs")]
[PrimaryKey("JobId", AutoIncrement = true)]
[Cacheable("Jobs", CacheItemPriority.Default, 20)]
[Scope("ModuleId")]
class Job
{
public int JobId { get; set; }
public int ModuleId { get; set; }
public string JobTitle { get; set; }
public int CategoryId { get; set; } //JOIN ME

public IEnumerable<Job> GetJobs(int moduleId)
{
IEnumerable<Job> t;
using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<Job>();
t = rep.Get(moduleId);
}
return t;

That CategoryId joins to another table. In that table is CategoryName, which I want to pull in when doing selects. I could use some real examples on how the DAL 2 does joins. I feel this is really lacking in the documentation.

From what I can tell, I can add

[IgnoreColumn]
public string CategoryName{ get; set; }

But how do I populate the column it in my controller? I feel like I'm missing something obvious.

 
New Post
3/12/2013 5:03 AM
 

You need to join at database level or:

1) public Category Category {get; set;}

or

2) public  string CategoryName { get; set; }

end edit your controller here

public IEnumerable<Job> GetJobs(int moduleId)

{
IEnumerable<Job> t;
using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<Job>();
t = rep.Get(moduleId);

}

 foreach (var item in t)

{

//1)

t.CategoryName = = YourCategoryController.GetCategoryNameById(t.CategoryId);

//or 2)

//t.Category = YourCategoryController.GetCategoryById(t.CategoryId);

}

return t;
}
 
New Post
3/12/2013 9:21 AM
 
Thank you for the consise reply. I came to the same conclusion, however at one point I almost created a sproc.  Cheers!
 
New Post
8/15/2014 12:32 PM
 
Expanding on this how would you do something like if you had multiple categories for your jobs? LIke for example a job can belong to two different categories? So on the database level I would have a third table that would map the jobId to the categoryId...how would you bring that together in DAL2?
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDAL 2 JoinsDAL 2 Joins


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out