Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RE: Want to show manufacture name in label when using EntityDataModel and relational db 1

Status
Not open for further replies.

AndyH1

Programmer
Jan 11, 2004
350
GB
I'm trying to get the hang of using Entity Data Sources and have created a simple database consisting of the two tables

Manufacturer
============
ManufacturerId (int)
NanufactureName (varchar)

Software
=========
SoftwareId (int)
ManufacturerId (int)
SoftwareName (varchar)

The two tables link on ManufacturerId

Ive created a EDS for these and a dropdownlist listing manufacturers using a EntityDataSource (which gets the manufacture table) and a Gridview using the EntityDataSource which uses the EDS to get software table.

The Gridview has edit/delete (so needs to use the Software table as its source) and Ive managed to bind a dropdown in the editTemplate of this to the ManufacturerId whilst getting the list from the ManufactureDataSource so that when people select edit it shows a dropdown list of manufacturers with the one corresponding to the ManufacturerId in the software list selected - this works fine and they can change and update this.


My problem is in the ItemTemplate I want the label to show the Manufacturer name, not the manufacturerId, but I cant figure how to do this. The label control cannot be linked to a different datasource (as far as I can see). If I use a view or stored procedure as the datasource (ie making a view in which the two tables are inner joined so it returns the manufacturer name) I cannot do updates, inserts etc in the gridview as it would try updating the view and not the software table

Could anyone please advise me how to get round this in EntityDataModels. I have managed with ObjectDataSourceModels and SQLdataSourceModels but cannot see anyway of doing this with EntityModels, as each entity corresponds to a table.

Thanks
Andy
 
If I understand what you want, you need to use LINQ to entities. You need to write a LINQ statement that joins the 2 tables, just as you would with a SP.
I don't ever use the datasource controls for anything because they are worthless once you want to do something a little complicated.
 
Thanks jbenson001. I finally worked out how to get the label to display the name, rather than the key using the include="" field in the datasource and then using an Eval in the Grid to give the name ie Text = '<%# Eval(Manufacture.ManufacturerName %>'

I know what you mean about datasources, they always look great in the demos, but as soon as you use them for real work, like you said, they tend not to fit. I much prefer coding myself, but often I am modifying other peoples work so need to understand their use so I can modify existing code.

Seeing as you are a long term programmer could I ask your opinion on MVC. Do you think it is the way to go, Im trying hard to get my head around it and it does seem complex...



 
I don't know much about MVC. I have looked into a bit once I say that MS included the template in VS2010. Many people rave about it. After I looked at it I decided not to go that route. To me, it seems like taking a step backwards to classic ASP where now you are back to mixing code with markup. To me this seems like going backwards. I like having my code separated from the markup. The big point of MVC is that the programmer has complete control over the HTML it renders. This is mainly due to the fact that you no longer use the server controls provided by .NET. Which again to me is going backwards. There are many people who don't like viewstate and the HTML that server controls render. It all depends on your school of thought.

MVC also touts that it is easier to test and to write test plans for. This may be true, but I have worked for many large and small corporations. I have even been sent to classes to use 3rd party testing tools. And in the end, I never wrote a test plan. Unless it is a very small app or your corp. has the money to have a separate team to write test plans, this most likely won't happen.


You can read up on it here and see if it fits for your business:


You can also take a look at how to build an MVC app:

Basically, if you have been doing web forms, it will take some time to get used to the MVC way of doing things and vice versa. The first article I posted lists the pros and cons of each. Personally, I have found no reason after many years of web forms programming to change my way of thinking to use MVC. I can create the same model design and still have access to server controls.

So, my advice, read up on it. Look at some examples, and try creating a test application and see if it makes sense for you and your coding needs to use MVC or web forms.

Good luck,
Jim
 
Thanks jbenson001. I did some reading up on MVC before posting and came up with similar views to what you said, so its useful to see them mirored. I used to be a classic asp programmer before .net, and thought, like you, the going back to mixing of code and html was a step back. I didnt really see it useful for web sites. For webservices it seemed it might be a bit more useful, but I havent used it yet for any real projects though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top