The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Dynamic Query, Collection Issue

Last post 03-19-2008, 10:43 AM by Mike.Griffin. 5 replies.
Sort Posts: Previous Next
  •  03-19-2008, 3:00 AM 8462

    Dynamic Query, Collection Issue

    ES version : 2007.1.1210.0
    SQL server 2005 / ASP.Net 2.0

    Hello, i'm using a dynamic query to populate a collection.
    Code is compiling and executing well, but collection is not populated because the DataTable in OnQueryLoaded is empty (rowcount = 0).
    The generated SQL Code is ok. I catch it with SQLProfiler and play it in a queryAnalyser, it's ok, it return 3 rows. but in OnQueryLoaded Method, DataTable has 0 row.

    I past the code below.
    Thanks for your help.

    AppCode :            

     

    Code:
    1                    CMSArticleCollection vArticleCollection = new CMSArticleCollection();
    2 vArticleCollection.es.Connection.Name = Constantes.ConnexionStringName;
    3 CMSArticleQuery vQArticle = new CMSArticleQuery("QArticle");
    4 ArticleTagingQuery vQArticleTaging = new ArticleTagingQuery("QArticleTaging");
    5 vQArticleTaging.es.Connection.Name = Constantes.ConnexionStringName;
    6 if (pTypeArticleId.HasValue)
    7 {
    8 vQArticle.Where(vQArticle.TypeArticleId.Equal(pTypeArticleId.Value));
    9 }
    10 if (pSousRubriqueId.HasValue)
    11 {
    12 vQArticle.Where(vQArticle.SousRubriqueId.Equal(pSousRubriqueId.Value));
    13 }
    14 if (!string.IsNullOrEmpty(pStatus))
    15 {
    16 vQArticle.Where(vQArticle.ArticleStatus.Equal(pStatus));
    17 }
    18 else 19 {
    20 vQArticle.Where(vQArticle.ArticleStatus.NotEqual(Constantes.Status.Deleted));
    21 }
    22 if (pTagIdList != null)
    23 {
    24 if (pTagIdList.Count > 0)
    25 {
    26 //Filtre Sur les Tags 27 string[] vStringTagIdList = new string[pTagIdList.Count];
    28 for (int i = 0; i < pTagIdList.Count; i++)
    29 {
    30 vStringTagIdListIdea = string.Format("{0}", pTagIdListIdea);
    31 }
    32 vQArticle.InnerJoin(vQArticleTaging).On(vQArticle.ArticleId == vQArticleTaging.ArticleId).Where(
    33 vQArticleTaging.TagId.In(vStringTagIdList));
    34 }
    35 else 36 {
    37 38 //Articles sans Tags 39 vQArticle.LeftJoin(vQArticleTaging).On(vQArticle.ArticleId == vQArticleTaging.ArticleId).Where(
    40 vQArticleTaging.TagId.IsNull());
    41 }
    42 }
    43 if (pArticleOrderMin.HasValue)
    44 {
    45 vQArticle.Where(vQArticle.ArticleOrder.GreaterThanOrEqual(pArticleOrderMin.Value));
    46 }
    47 if (pArticleOrderMax.HasValue)
    48 {
    49 vQArticle.Where(vQArticle.ArticleOrder.LessThanOrEqual(pArticleOrderMax.Value));
    50 }
    51 52 foreach (OrderItem vOrderItem in pOrderItems)
    53 {
    54 vQArticle.OrderBy(vOrderItem.ColumnName, vOrderItem.Direction);
    55 }
    56 vArticleCollection.Load(vQArticle);
    57 return vArticleCollection;

    Generated SQL:

     

    exec sp_executesql N'SELECT * FROM [CMSArticle] QArticle WHERE QArticle.[SousRubriqueId] = @SousRubriqueId1 AND QArticle.[ArticleStatus] = @ArticleStatus2 AND 
    QArticle.[ArticleOrder] >= @ArticleOrder3 AND QArticle.[ArticleOrder] <= @ArticleOrder4 ORDER BY [ArticleDateManuelle] DESC'
    ,N'@SousRubriqueId1
    uniqueidentifier,@ArticleStatus2 varchar(9),@ArticleOrder3 int,@ArticleOrder4
    int'
    ,@SousRubriqueId1='28F51CA5-1B05-4071-B1F2-A4FB0468AEAD',@ArticleStatus2='Published',@ArticleOrder3=0,@ArticleOrder4=0

     
  •  03-19-2008, 6:03 AM 8464 in reply to 8462

    Re: Dynamic Query, Collection Issue

    Hmm, we have never had a valid SQL query not bring data back in EntitySpaces.

    Can you just check.vArticleCollection.Count after the load, without debugging. Perhaps it is the connection name assignments. Why are you doing those?


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  03-19-2008, 6:43 AM 8469 in reply to 8464

    Re: Dynamic Query, Collection Issue

    Thanks for your answer, and sorry for my bad english of french developpeur :) 

    I checked vArticleCollection.Count after the Load, value=0

    the same issue append in OnQueryLoaded, the DataTable Parameter has a RowCount equal to 0 to.

    I use connection name assignement because  i use multiple database for this project (3 projects with business classes on separate database and one webapplication project for the BackEnd/FrontEnd).

    i'll try to not assign connection name in code and test the function.

    thank you.
     

  •  03-19-2008, 6:56 AM 8470 in reply to 8469

    Re: Dynamic Query, Collection Issue

    Hi

    Just an idea - if the SQL is valid, and runs (returning rows) in SQL profiler fine, then could it be anything to do with permissions for the user that you're connecting to the DB through in your code/connection string?

    As I say, just an idea

    Thanks

    Martin

  •  03-19-2008, 10:11 AM 8471 in reply to 8470

    Re: Dynamic Query, Collection Issue

    The user is the same.
    but, i found my error : i was using a bad connection name for my businessclasses. (thanks to Mike to put me on the way).

    Something throw me on the bad way since start of developpement :
    in "connectionInfo" section in web.config, "default" attribute is working well... the connection name was not well typed in my code, and le default connection was used by entityspaces :)
    I dont explain why request was passing in sqlprofiler well and retrieve data, but it work fine now. Party!!!

    Thanks for your help.

    And thanks to entityspaces developers, i really love this persistance layer.

  •  03-19-2008, 10:43 AM 8472 in reply to 8471

    Re: Dynamic Query, Collection Issue

    Awesome, and by the way, your English is just fine Yes, I couldn't begin to use another language, so never apologize for that Big Smile

    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML