Jennings ORM challenge

Posts   
 
    
PilotBob
User
Posts: 105
Joined: 29-Jul-2005
# Posted on: 03-Jan-2007 19:34:09   

Him,

I just read Roger Jennings article in October 06 Visual Studio Mag Objectify Data with ADO.NET vNext. In it on page 25 he shows the following code, saying it will get a list of all SalesMan and bind it to the grid:

Using AWv3 As New AdventureWorksV3 Dim SalesPersons As Query(of SalesPerson) _ = AWv3.GetQuery(of SalesPerson)("SalesPerson")

dvgSalesPerson.DataSource = SalesPeople.toList End Using

(Notice he didn't call databind, don't you need to do that here?) Of this code he says the following:

"[b]I doubt if you could find a competitive O/RM technology to fill a grid with fewer lines of code[/b], but the column order of the DataGridView doesn't come close to resembling the EntityType's Proerty elements' order."

I expect someone here could show up Mr. Jennings?

BOb

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39797
Joined: 17-Aug-2003
# Posted on: 03-Jan-2007 20:31:28   
EntityCollection<SalesPersonEntity> salesPersons = new EntityCollection<SalesPersonEntity>();
using(DataAccessAdapter adapter= new DataAccessAdapter())
{
    adapter.FetchEntityCollection(salesPersons, null);
}
dgvSalesPerson.DataSource = salesPersons;

or vb


Dim salesPersons As New EntityCollection(Of SalesPersonEntity)()
Using adapter As New DataAccessAdapter()
    adapter.FetchEntityCollection(salesPersons, Nothing)
End Using
dgvSalesPerson.DataSource = salesPersons

sniff cry one line extra... wink

DataBind() isn't needed in winforms, I think he uses winforms (datagridview)

His code has a sucky string value as well... very typesafe! wink , plus 'GetQuery'... isn't that some generated code somewhere?

His remark about property order is also funny, he really doesn't understand how databinding works apparently heh simple_smile

Is this article visible online somewhere?

Frans Bouma | Lead developer LLBLGen Pro
psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 03-Jan-2007 21:22:14   

Won't this work (I can't check it right now)?


using(DataAccessAdapter adapter= new DataAccessAdapter())
{
    adapter.FetchEntityCollection(new EntityCollection<SalesPersonEntity>(), null);
}
dgvSalesPerson.DataSource = salesPersons;

EDIT: Of course not, duh.

I meant . . .


using(DataAccessAdapter adapter= new DataAccessAdapter())
{
     dgvSalesPerson.DataSource = adapter.FetchEntityCollection(new EntityCollection<SalesPersonEntity>(), null);
}

. . . but I don't think FetchEntityCollection returns the collection, so never mind. flushed

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 04-Jan-2007 06:50:40   

Code:

using(DataAccessAdapter adapter= new DataAccessAdapter()) { dgvSalesPerson.DataSource = adapter.FetchEntityCollection(new EntityCollection<SalesPersonEntity>(), null); }

. . . but I don't think FetchEntityCollection returns the collection, so never mind

Why do you think so?

BertS
User
Posts: 89
Joined: 28-Jul-2005
# Posted on: 04-Jan-2007 10:26:07   

In SelfService:

Dim SalesPersons As New SalesPersonsTypedList
SalesPersons.Fill()
dvgSalesPerson.DataSource = SalesPersons

stuck_out_tongue_winking_eye

He's also using a predefined query (as Frans points at, with GetQuery), so that's allowed for us too (instead of TypedList, it could of cource be a TypedView) LLBLGen is typesafe simple_smile

**LLBLGen Pro is the WINNER smile **

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 04-Jan-2007 15:45:41   

Walaa wrote:

Code:

using(DataAccessAdapter adapter= new DataAccessAdapter()) { dgvSalesPerson.DataSource = adapter.FetchEntityCollection(new EntityCollection<SalesPersonEntity>(), null); }

. . . but I don't think FetchEntityCollection returns the collection, so never mind

Why do you think so?

I'm not sure I understand your question?

PilotBob
User
Posts: 105
Joined: 29-Jul-2005
# Posted on: 04-Jan-2007 16:32:30   

Otis wrote:

sniff cry one line extra... wink

DataBind() isn't needed in winforms, I think he uses winforms (datagridview)

Ah, you're probably right... I just live in my little Asp.net world!

Otis wrote:

His code has a sucky string value as well... very typesafe! wink , plus 'GetQuery'... isn't that some generated code somewhere?

Um, I assume GetQuery is part of the "db object" or whatever they call it. But, it could be generated by the EDM framework. As you say, this example uses eSQL... but he goes on later to say you can use LINQ to write the query and it would be typesafe. The reason I think he did it this way is that if you essentially want "SELECT * FROM Entity" they you just have to provied the entity name as the query.

Although, I'm not sure a goal of writing easy to maintain code is to be as terse as possible, I seem to see alot of articles that are proud of how cryptic they can make a "single" line of code.

Otis wrote:

Is this article visible online somewhere?

Yes, it seems to be:

http://www.ftponline.com/vsm/2006_10/magazine/features/rjennings/

BOb

PilotBob
User
Posts: 105
Joined: 29-Jul-2005
# Posted on: 04-Jan-2007 16:34:39   

BertS wrote:

He's also using a predefined query (as Frans points at, with GetQuery), so that's allowed for us too (instead of TypedList, it could of cource be a TypedView) LLBLGen is typesafe simple_smile

It is not really a predefined query. As I said in my other post... he stated that basically if you want to write the query "SELECT * FROM EntityName" then you just need to pass the entity name, it will assume all columns with a where clause.

BOb

BertS
User
Posts: 89
Joined: 28-Jul-2005
# Posted on: 04-Jan-2007 17:02:36   

PilotBob wrote:

BertS wrote:

He's also using a predefined query (as Frans points at, with GetQuery), so that's allowed for us too (instead of TypedList, it could of cource be a TypedView) LLBLGen is typesafe simple_smile

It is not really a predefined query. As I said in my other post... he stated that basically if you want to write the query "SELECT * FROM EntityName" then you just need to pass the entity name, it will assume all columns with a where clause.

BOb

Ok, but then we can take a collection and call a getmulti. Same linecount simple_smile

louthy
User
Posts: 61
Joined: 02-Aug-2005
# Posted on: 09-Jan-2007 02:06:16   

How about one line, self-service:

dvgSalesPerson.DataSource = (new SalesPersonTypedList()).Fill();

Not pretty, but works.

MatthewM
User
Posts: 78
Joined: 26-Jul-2006
# Posted on: 09-Jan-2007 17:06:33   

Just my 2 bits here. Isn't the whole thing really moot? Seriously, I don't know the last time I wrote production code without a middle layer...so I can reuse those 500 character one liner obfuscated messes wink