newbie question

Oct 22, 2012 at 4:11 PM

Hi,

I'm developing apps using Mono for android and Monotouch, and I was looking for an ORM to implement the database infrastructure.  I came across OpenNETCF.ORM, and started implementing it in my project.

I have a query which looks like this:

Select * from customers where idAreaManager=@idAM and (customerName like @filter or customerCode like @filter or customerNotes like @filter)

How would I translate such a query using the Select<T> method?  Or is there a better way?

Also, is it possible to execute queries using sql and having mapped objects in return? 

 

How would I go about using Select with Joins?  It's a pity there is not much documentation nor sample projects (beside the basic one that just shows how to map classes), because the project looks interesting.

 

Please advice.. thank you.

Fabio

Coordinator
Oct 23, 2012 at 5:03 PM

Yes, I have to apologize (again) for the lack of good documentation or examples.  I rarely find or make the time to document this project (or really any of my many projects).  typically it's becasue I'm pretty busy using them.  I'll see what I can do to create some documentation for your specific instances, but in the meantime, I can at least give some guidance.

1. For Select with filter conditions you have a few options.  If the expected unfiltered result set is small, you can pull everything and then use LINQ to filter (since the CF doesn't support Expressions, we can't do much to help out there).  There is also the FilterCondition array that can be passed in.  Play with that to get the ORM to generate SQL for the query for you.  It's more limited than what you can get writing full-up SQL, but it works for a lot of things.

2. You can execute direct SQL, but only as an "ExecuteNonQuery" or "ExecuteScalar".  There's no way (currently) for the ORM to execute an SQL statement and return the results as typed objects (or any object for that matter - the point of the ORM is to hide the implementation of the store). Largely the ORM can't convert the result of a SQL statement becasue it has no simple way to map the results to entities.  I could do some work on that end, but it would be a rats nest I think.  What if you only select a subset of fields?  What if you use Joins?

3. It depends on your JOINs. If it's simple 1:n references, then the Reference fields do that.  Take a look at some of the sample/test code covering references.  If it's mroe complex, then I'd need a better idea of what you're after.

Generally speaking, if you're using an ORM (any ORM, not just this one), you need to break free of the mindset of "joins" and SQL in general.  You're dealing with entities/objects and instances.  Not tables and rows. 

 

Oct 23, 2012 at 5:15 PM

Thank you for your answers.

I've already started implementing my code.  I'm testing OpenNetCF in an app i was developing with Catnap.orm, which is quite nice, but was giving me headache on Updates.

Catnap supports hydrating objects using sql (obviously you have to select fields only from a single mapped table).  

I'm testing some slight modification to your library that would allow me to do that, but it will take some time for my porting to be complete and start testing...

You don't need to apolgize for lack of documentation... we software developers all lack in that area :P

It's more important to have more sample projects with a little more complex objects and queries, and we can learn from that (even some sample code).

I'll post my progress / cries for help :)

 

Thank you for putting your effort in this project... it' s much appreciated :)