How does getRolesResult get created?

How does getRolesResult get created?

Old forum URL: forums.lhotka.net/forums/t/8130.aspx


FCazabon posted on Friday, December 11, 2009

Hi,

How does the getRolesResult class get created in PTracker.designer.cs in the ProjectTracker sample project?

My impression is that this program gets created by the SQL to Link stuff, but in my case I am not getting this class created.

I saw someone else asked this same question previously here: http://forums.lhotka.net/forums/post/23790.aspx
but they didn't get any answer.

RockfordLhotka replied on Friday, December 11, 2009

There is a getRoles stored procedure, and I dragged that sproc from the Server Explorer onto the LINQ to SQL design surface. That caused L2C to create code to wrap the sproc so it can be invoked like a .NET method.

FCazabon replied on Friday, December 11, 2009

Hmm...

I have a stored procedure:

CREATE PROCEDURE [dbo].[getMembers]

AS
SELECT Id, FirstName, MiddleName, Surname, Mobile, [Work], Home, LastChanged
FROM Members
RETURN


which I dragged just as you did, but I don't get a getMembersResult() method in my members.designer.cs, I get a

Looking at the getRoles procedure in PTracker I see it is pretty much the same as mine:

CREATE PROCEDURE [dbo].[getRoles]

AS
SELECT Id,Name,LastChanged
FROM Roles
RETURN


is there some trick to getting the getRolesResult() to generate? I see there are a few other ...Result() in PTracker.designer.cs, but none of my getXXX() stored procedures have generated a getXXXresult().

RockfordLhotka replied on Friday, December 11, 2009

I don't know - I quit using L2S a while back (as a general rule) once it was
clear that Microsoft was not taking that technology forward. Strategically
you should consider using EF, as that's the future direction they are going.

FCazabon replied on Monday, December 14, 2009

I really don't know what to say.

Using EF is fine, but where can I find instructions on using it and CSLA similar to what you did in the book? Do you have an update on your blog or elsewhere?

Maybe you should have a disclaimer somewhere saying: don't follow the example in the book as it is out of date.

triplea replied on Monday, December 14, 2009

Check this post:

http://forums.lhotka.net/forums/thread/31326.aspx

You will find a link to Sergey's blog where he has an example.

Also, stop using LINQ to SQL was a suggestion. It still works perfectly fine it is just that MS does not have plans to continue enhancing it in favour of EF. So if you are starting off now you are off better using EF. It is a bit like the Winform/WPF argument and countless other similar examples. I think the disclaimer you mention is a bit of a wrong sugestion...

The main thing to remember is that CSLA does not depend on any data access technology.

FCazabon replied on Monday, December 14, 2009

Thanks for the link, it doesn't take me to a particular article and Sergey's blog has moved to http://dotnetspeak.com. I've tried to search for any relevant looking article there but I'm not sure which one in particular that thread was referring to.

I understand switching to EF was a suggestion, and I have no problem with it as I am aware that the general consensus has been to stop using Link to SQL, but I was just following the example in the book.

With respect to the disclaimer, if Rocky is not going to offer any assistance in working through the example in the book when it comes to the Link to SQL stuff, maybe he should have a disclaimer stating that.

I'm just a little frustrated that I bought the book which is only a year old, that has an example on how to do something, so I am following the example and encounter a problem only to be told, don't use that technology any more, after I've spent many hours trying to work out what I have done wrong.

I am not trying to come across as being ungrateful, I truly appreciate the work that has gone into CSLA.NET and the fact that it is practically free, but as someone coming in new to this I have found it quite difficult to know where to start and to get guidance and the frustration is getting to me :(

RockfordLhotka replied on Monday, December 14, 2009

Again, I don't know what to suggest. I can't control what technologies
Microsoft decides to take forward (or not)... Personally I really like L2S
and wish it had a future...

But I am also not Microsoft support. You are obviously running into an issue
with the L2S designer, not CSLA .NET. I have never claimed to support all of
.NET and every product and designer in VS. I am a user of these things just
like you are.

Microsoft has hundreds (thousands?) of people called Product Support
Services that they pay to provide support for these things. I try to be
smart, but there's no way I can replace all of PSS through this forum.

There are also entire forums on MSDN devoted to various Microsoft tools and
technologies. I can't pretend to replace those on this forum either.

I understand you are frustrated. I've been there (I actually am there
frequently - remember that I'm usually using these tools months before they
are released, so they are much less reliable). But that doesn't change the
reality that I can't provide support for Microsoft products and designers
just because I decide to use them in some sample app.

FCazabon replied on Monday, December 14, 2009

I don't expect you to support MS products, but I tend to think that I have done something wrong/different in creating my stored procedures/database.

If anyone here is familiar with L2S, I would appreciate their input. My problem is this:

If I create a new L2S class, drag the getRoles stored procedure into it, I get the getRolesResult() generated

If I create a new L2S class, drag my getMemberShipTypes stored procedure, I don't get a getMembershipTypesResult() generated.

So my assumption is that I have not set up something in my database that has been set up in the PTracker database.

If anybody has a clue as to what that could be I'd really appreciate it.

My only aim here is to learn how to use CSLA .NET properly and so I am just trying to follow the example in the book, adjusting it for a simple database I have created. I will take the advice given here and switch to EF, but first I'd like to just get my simple app working the same way the PTracker sample works.

RockfordLhotka replied on Monday, December 14, 2009

My first thought was that Microsoft might have changed the L2S designer
code-gen since I wrote the book (as that was pre-SP1). But you are saying
you re-created the getRoles code in VS now, so that clearly isn't the issue.

Does your getMembershipTypes sproc return the same type of data as getRoles?
Sprocs can return one set of data, multiple sets of data (not supported by
the L2S designer) or individual values, perhaps that's different?

FCazabon replied on Monday, December 14, 2009

When I edit the code in PTracker, this is what I get:

ALTER PROCEDURE [dbo].[getRoles]

AS
SELECT Id,Name,LastChanged
FROM Roles
RETURN


My code in my database is:

ALTER PROCEDURE [dbo].[getMemberShipTypes]

AS
SELECT Id, Name, LastChanged
FROM MembershipTypes
RETURN


The only difference I can see is that Id in Roles is an int, whereas I have it set as a uniqueidentifier.

ajj3085 replied on Monday, December 14, 2009

Hi,

Linq2Sql designer will only create a class call spNameResult if it returns data which doesn't match any entity for a table.  In your case, it looks like you're just returning all the fields from your Member table, so you spName code will probably just return an IEnumerable<Members>.

Are you finding its doing something else?

Andy

FCazabon replied on Monday, December 14, 2009

Hi Andy,

the getRoles in PTracker looks like it returns all fields from the Roles table, yet a getRolesResult was generated. Can you explain why?

FCazabon replied on Monday, December 14, 2009

Hmm... hold on a minute!

I just found the problem! getMemberShipTypesResult exists, but the one I was typing in getMembershipTypesResult did not exist.

Can you spot the difference?

I was using "ship" not "Ship"!!!!

Lesson learned: use intellisense when it is available.

I'm really sorry to have wasted yours and Rocky's time here.

triplea replied on Monday, December 14, 2009

No worries. The example projects are indeed in that link (even if it is his old blog):

http://sergeybarskiy.spaces.live.com/default.aspx

Just scroll completly to the bottom of the page. You will find a box labelled SkyDrive and Public Folders. I think the one you want is "AtlantaCodeCamp2009". The direct URL is:

http://cid-2383900f69b808e0.skydrive.live.com/browse.aspx/.res/2383900F69B808E0!244

But if it is simplicity you are after you can always just use simple ADO. SQL Connections/Commands/Readers etc, they still do the trick.

Happy coding.

Copyright (c) Marimer LLC