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...Getting StartedGetting StartedDAL2 - SELECT NULLDAL2 - SELECT NULL
Previous
 
Next
New Post
10/7/2013 9:57 PM
 

I am trying to use the DAL2 in a module and having some issues with selecting things from the database.  When I use a SQL Profiler to look at the SQL that makes it to the database I am seeing queries that do not specify the field names to select.  The statement is starting off "SELECT NULL".  Here is a more complete view of what I see:

exec sp_executesql N'SELECT NULL FROM [Product] WHERE [productCode]=@0',N'@0 nvarchar(4000)',@0=N'ANDY' 

The SQL above was produced by the GetById() function of the IRepository. Here is the code:

public Product GetItem(string key)
        {
            Product t;
            using (IDataContext ctx = DataContext.Instance(EXTERNAL_DB_CONNECTION_STRING))
            {
                var rep = ctx.GetRepository<Product>();
                t = rep.GetById(key);
            }
            return t;
        }

The field names in my class file all match the database field names.  I have specified the TableName(), PrimaryKey(), and Cacheable() in my class file.

What needs to be done so the fields will be selected?

 
New Post
10/8/2013 2:48 PM
 

Here are some additional code details to make the sample complete.

Product.cs:

using System.Web.Caching;
using DotNetNuke.ComponentModel.DataAnnotations;
namespace MyModule.Components
{
    [TableName("Product")]
    [PrimaryKey("productCode")]
    [Cacheable("MYMODULE_Product_", CacheItemPriority.Default, 20)]
    [Scope("productCode")]    //tried different values here and nothing changed but excluding this caused more problems
    public class Product
    {
        public string productCode;
    }
}

ProductRepository.cs:

using DotNetNuke.Data;
namespace MyModule.Components
{
    public class ProductRepository
    {
        private const string EXTERNAL_DB_CONNECTION_STRING = "MY_DB_CONNECTIONSTRING_NAME";

        public Product GetProduct(string productCode)
        {
            Product t;
            using (IDataContext ctx = DataContext.Instance(EXTERNAL_DB_CONNECTION_STRING))
            {
                var rep = ctx.GetRepository<Product>();
                t = rep.GetById(productCode);
            }
            return t;
        }
    }
}

Code In View.ascx.cs:

ProductRepository productRepo = new ProductRepository();
Product product = (Product)productRepo.GetProduct("MYCODE");

Resulting SQL:
exec sp_executesql N'SELECT NULL FROM [Product] WHERE [productCode]=@0',N'@0 nvarchar(4000)',@0=N'MYCODE'

Resulting SQL if the Scope attribute is removed from Product.cs:
SELECT NULL FROM [Product]  

If additional information is needed, please let me know.  Thanks.

 
New Post
10/8/2013 7:24 PM
 

I discovered the problem is related to the field definitions in the object file.  To make DAL2 discover the fields and use them in queries, the fields need get and set accessors.

 public string productCode; //This will not be mapped to the database field using DAL2

public string productCode { get; set; }// This will be mapped to the database field using DAL2

If anyone has additional information about why this is a requirement, or a link to documentation showing that this is a requirement, please add it to this thread.

Good luck and happy coding!

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Getting StartedGetting StartedDAL2 - SELECT NULLDAL2 - SELECT NULL


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