 |
| ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 13th, 2013, 05:32 PM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Connecting Controls Up to Data in/from Multiple Locations
Using Visual Web Developer 2010 (and still trying to work my way through Imar Spaanjaars "Beginning ASP.NET 4").
Working in C#.
Trying to see if I can work with Entity Framework.
What is supposed to be the best way to create a form so it can save particular pieces of new submissions into multiple databases? (A new member enters in their personal info, with the physical address being saved to a separate database, to leave open the possibility of adding in more addresses later.) If accurate, I'm finding that .NET will not allow inserting/editing on tables associated as "navigation" properties of the entity. Navigation properties can only be displayed. So far, as a .NET novice, in order to create this form, I'm seeing 3 ways:
A) Create 1 DetailsView control sourced from an entity that represents the table containing the bulk of the form's info; and then, after inserting the new fields that can be inserted, programmatically insert the address fields (probably using a 2nd entity based on the addresses table). I haven't tested this theory yet.
B) Create 3 DetailsView controls - the 1st connected to the main entity; 2nd connected to the addresses entity; and the 3rd connected to the main entity again, set to update by default. (I want/have to make the form in 3 sections in order to maintain some coherency to the order of items requested - name, phone, email; addresses; followed by errata pertaining to the membership.) Then, w/ the controls in place, set up a chain of events to fire after the 1st control inserts - grab the unique id, trigger insert on the 2nd form, and then fire the 3rd to update the member record w/ its info. I tested a truncated version of this, and got it to work; I didn't just run w/ it because I realized the last form would require updating vs inserting. I could hide each subsquent section until the 1st is filled in, and pass info forward. What a fussy mess.
C) Use an SqlDataSource w/ the DetailsView control, and manually write its INSERT statement. But that requires I don't run into some new roadblock while experimenting. And what's the point of all this fancy-schmancy OOP if I have to manually write out the SQL statement, and create a bunch of templates in the control for each field and bind them all up by hand.
So my question is: what might be the "normal" or more common way someone w/ better understanding of .NET would put this form together?
Thank you for any clarity anybody can provide for all this.
|
|

May 13th, 2013, 09:21 PM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
OK. Successfully cleared up all the issues around trying to work with all the controls in one form and grab the data back out of the non-bound ones. Now I have to see how easily I can get them into a new "Address" entity. Trying to just create a new "Address" directly, but I still want to see, per my original intention, whether I can use the "Addresses" EntityDataSource to do the heavy lifting, since I went through the trouble of creating one and all, and totally seems like this sort of operation is something that should be accessible in a datasource.
|
|

May 14th, 2013, 05:41 PM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
And now I'm trying to get past problems implementing a class that's supposed to expose an Insert method on EntityDataSource controls, per:
http://forums.asp.net/t/1621469.aspx/1
and
http://social.msdn.microsoft.com/for...-d7ce912f46c2/
VWD is telling me that "The type or namespace name 'EntityDataSource' could not be found." (.NET compiler error CS0246) for the class itself. I haven't even tried using it yet.
So I haven't been able to make progress experimenting with making an EntityDataSource do the insert. (Apparently it was not a priority to use EntityDataSources this way.)
|
|

May 15th, 2013, 06:50 PM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm quickly (hehe) coming to the conclusion that the only truly workable solution for any degree of complexity is an SqlDataSource, since I can just manually write the freaking SQL I need. Of course, I haven't actually done that yet and am just starting now to try this approach, soooo ... what could possibly go wrong!?
The EntityDataSource.Insert() using the extension to the EntityDataSource controls just isn't working. Acts like it's going to, now that I got past the compile problem, but I can't apparently get any actual data into the properties during the Inserting event. Not working for me, anyway.
http://forums.asp.net/p/1621469/5395...42370304176273
So, one DetailsView based on an SQLDataSource coming up next!
|
|

May 15th, 2013, 09:49 PM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well, holy #@*^in' hallelujah.
The SqlDataSource worked with no real hitches.
(But, man, the DetailsView is still a gnarly lookin' monster.
Looking like FormView will be the mode for everything except back-end management of anything but the simplest, plainest data.)
(Procedural VBScript doesn't seem quite as cumbersome anymore;
and thoughts of PHP make me happier and happier all the time.
What is the point of all this new-fangled .NET / OOP / IDE shtuff when, in the end, you have to customize and hand-code in a procedural fashion anything that's slightly more complex than "Hello World" anyway, and still use a whole bunch of external tools to determine what's wrong? Why was it not a priority to make something like the Entity Framework handle such complexity? The Entity Model knows how it's all connected already! It knows how it all hooks up. Why can that not be made to handle common, multifaceted operations involving everything it already knows about?)
*sheesh*
Now to add validation and styles (and deal with all the weird, limited, humongoloid ID system that Microsoft thought was a good idea. Why are hyphens not allowed in IDs? Why does a control need its parent's ID prepended?)
OK. I'll quit now...
|
|

May 16th, 2013, 03:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You may want to check out the section "Hand-Coding Data Access Code" in CHapter 15, page 554 of my book Beginning ASP.NET 4. It describes how to use your own controls and program against the EF model directly. For complex pages (as you seem to be having) this is a much better solution.
Cheers,
Imar
|
|

May 31st, 2013, 01:40 PM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ha! Ironically, that's the chapter I'm trying to get through now; but I'm backpeddling to the Javascript sections since I skipped those in order to jump ahead to the database and EF/LINQ chapters. The Javascript chapters put in place things I need in the sample site in order to proceed smoothly through the "Advanced Topics" section.
I'm communicating with someone else, too, who manages .NET projects; and he's also recommending programming directly against EF as the way to go.
I'll get there, I guess. I just have to work more with objects and EF to better assimilate how all this goes together.
Thanks for the reply!
|
|

May 31st, 2013, 03:10 PM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Another thing I just figured out, that's putting a damper on my EF joy:
I had 1 EntityDataSource drawing a list of states and abbrs from a database, and I was using those to populate a DropDownList, which was then bound to the SqlDataSource for my FormView.
I grabbed the Recaptcha .NET library, registered it in web.config, and placed the Recaptcha control in this same FormView.
For the longest while I was getting sporadic LoaderExceptions errors while trying to view the page. Everything seemed to point to something about the Recaptcha library or my handling of it. I remove it, no problems; put it back, page loads sporadically.
Finally, determined that somehow the EntityDataSource populating the DDL was interacting badly with Recaptcha. Remove the EDS, all else great - no problems loading the page consistently with Recaptcha present. I couldn't readily figure out how to populate the DDL using EF directly, so I resorted to an SqlDataSource again.
Anyway, just saying I have a bit to go before I fully "get" how to make EF work for me. Apparently using EntityDataSource controls as a shortcut is a problematic affair.
|
|
 |