New Posts New Posts RSS Feed: Using EntitySQL questions
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Using EntitySQL questions

 Post Reply Post Reply
Author
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Topic: Using EntitySQL questions
    Posted: 10-Nov-2011 at 6:35pm
Thanks for response! I already found that info on DRC. Reason I went with ESQL so I can decouple my model from my UI little better.
LINQ sounds much better from compile time validation standpoint. I will look over my code once again and see if I can use it.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 10-Nov-2011 at 6:14pm
Hi katit,
 
For the first problem, you can use the EntityMetadataStore to retrieve the entity set name for the entity type, which is what Esql is expecting here.  Something like,
  var entitySetName =  entityManager.MetadataStore.GetEntityMetadata(typeof(T)).DefaultEntitySetName;
 
An Esql query is always a "data source only" query, so doesn't take advantage of caching.  The entities are loaded into the EntityManager cache, however, so you can still do cache-only LINQ queries to retrieve and filter already loaded data.
 
If you switch to dynamic SQL, since these queries are LINQ queries you can take advantage of different query strategies, and cache query optimizations.  Dynamic SQL is actually intended for a situation like yours.   We don't have any full code samples, but there's quite a bit of information on the DRC - http://drc.ideablade.com/xwiki/bin/view/Documentation/dynamic-queries.
 
 
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Posted: 10-Nov-2011 at 10:23am
Consider this code that I use:
 

esqlString = "SELECT VALUE e FROM " + typeof(T).Name + "s AS e";

As you see, I've got generic class of <T> where T : Entity
 
So, when I need to get records for this entity - I use query above. Problem is that I have to add "s" to specify that I'm querying collection of <T>
 
1. I wonder if I can somehow use entityManager to get collection name if I know typeof(T) ? My main concern is that I'm hardcoding and I'm not sure how pluralizing really works. will it add "s" everywhere or there is exception list and I will get bitten by this one day?
 
2. I noticed that when I started using entity SQL - I don't get caching anymore. I wonder if there any techniques where I can achieve dynamic query and also retain caching? To get you an idea why I'm using esql:
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down