|
Demo Version
|
|
Download and try for yourself a fully working demo version, including sample apps and documentation. The only limitation is that the demo version only works inside the debugger.
|
|
Subscribe
|
|
Get It All for $50 USD:
WebPortal, ORMapper,
Source Code, All Updates
|
|
User Login
|
|
|
|
|
|
Wilson ORMapper Forums : OPath Queries : select only some fields
|
|
| 9/4/2006 3:35:13 PM |
Hi,
Doing that this (above) is the same as [ Select * from PageTemplate where TemplateId=templateId ]
-----------------
ObjectReader reader = DataManager.ObjectSpace.GetObjectReader(typeof(PageTemplate), "TemplateId=" + templateId);
-----------------
But I want to select only some fields from one table.
Suppose that I want [ Select TemplateName from PageTemplate where TemplateId=templateId ]
How can I do that ? Using OPathQuery? How ?
Note: Sorry...I suppose that is very basic but I new wilsonORmapper :p Thanks |
| 9/4/2006 4:55:58 PM |
If you want to only return a subset of fields then you have two options. One option is to define another object type with fewer properties, possibly having the "complete" object inherit from this smaller object, and then specifying that other object type in your queries. The other option is to use GetDataSet as one overload allows you to specify which fields -- you won't get an object back but sometimes you don't need objects. Why is this restricted? It may make sense that you only want some fields, but a partially loaded object doesn't really make sense because all of those properties are still accessible, not to mention it may make for invalid business logic.
Thanks, Paul Wilson
|
| 9/4/2006 8:55:48 PM |
Hi Paul,
The main idea is to reduce the network traffic. Some fields are not necessary in some cases and will increase the performance. I will try to use the other option, using the GetDataSet :p
Thanks :p
|
| 9/5/2006 9:14:30 AM |
Hi Paul,
I am doing something wrong ?
If I made this:
string query = "TemplateId=" + templateId;
ObjectReader reader = DataManager.ObjectSpace.GetObjectReader(typeof(VwPagesStatusPublished), query); if (reader.HasObjects) { .... }
The reader.HasObjects is true and yes is true, the reader have the result I expect.
If I made this:
string query = "TemplateId=" + templateId; string[] fields = new string[] { "PageId", "TemplateId" };
DataSet dataSet = DataManager.ObjectSpace.GetDataSet(typeof(VwPagesStatusPublished), query, fields);
if (dataSet.HasErrors) { ... }
The dataSet.HasErrors is false, the dataSet NOT have the result I expect and is WRONG. And yes, that fields exist in my table VwPagesStatusPublished!
It´s the same query and I want only that two fields ( "PageId", "TemplateId" ).
How can I see the "query" that was produce "behind the scenes" ? what I am doing wrong ?
Thanks |
| 9/5/2006 12:33:04 PM |
If you're working in VS in debug mode, you will see all the sql generated if you use the debug dll. Otherwise, you'll need to either run a profiler or implement the IInterceptCommand interface. If I understand you correctly you are getting incorrect results, not an exception -- can you give me a better idea of what data you are getting back? Correct or incorrect fields?
Thanks, Paul Wilson
|
| 9/5/2006 1:35:34 PM |
Hi Paul.,
Forget the problem, everything is working just fine! Sorry, also, for losing your time. While debugging I have seen that the query was correct build (the SQL statement was correct), the problem is not here!!
If you look at my code, see the bold I have made at dataSet.HasErrors.
DataSet dataSet = DataManager.ObjectSpace.GetDataSet(typeof(VwPagesStatusPublished), query, fields);
if (dataSet.HasErrors) { ... }
The problem is that my eyes always see (dataSet.HasRows) not the real command (dataSet.HasErrors) !!! Of course it always get false…. There was no ERRORS!!!
Sorry, again, for losing your time…. The problem is that I am several yours look at the screen and need some caffeine !!! :p
Thanks again for your support!
|
|
|