Solved

Problem associating linq view with table

Posted on 2011-02-24
9
575 Views
Last Modified: 2013-11-11
Hi EE,

I have a listview that is bound to my Products table.  Within this listview I have dropdownlists that are bound to a view.
The reason I am using a view is because I need to display 2 fields from different tables.
The primary key for the view is a key in the Products Table.
I keep receiving an error, saying... Message: DataBinding: 'Service2020.ProductsLU' does not contain a property with the name 'vBrandsTypes'.
I assume it is coming from...
 <asp:Label ID="lblProdcat" runat="server" Text='<%# Eval("vBrandsTypes.ProductType") %>' />

I tried dragging the view onto the table in the dataclass designer, but it did not work.
What can I do to get this to work?

Thanks
0
Comment
Question by:Sheritlw
  • 5
  • 4
9 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 34972170
To your statement, "I tried dragging the view onto the table in the dataclass designer, but it did not work.", a view is like a table so when you drag it on to the Linq to SQL design surface drag it to an empty area and NOT on top of another table.
0
 

Author Comment

by:Sheritlw
ID: 34972827
Yes, I know that.  I just thought I read somewhere that I could associate a view with table by doing that.
How can I get my view to link with the table?

Thanks
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 34973462
Hi Sheritlw;

Sorry I misunderstood you. Here is how you can do this.

1. In the design make sure you have your Products table and the View.
2. In the OR/M designer, drag an Association from the toolbox and click on the Primary key field
    in the Products table then click the field in the View that the primary associates with.
3. In the View click on the field which is to be the primary key which was selected in step 2 above.
4. Now open the Properties window and change the property "Primary Key" from False to True.
5. Save and compile, you should be good to go.

Fernando
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:Sheritlw
ID: 34973816
Hi Fernando,

I tried what you said, except for step # 4 (didn't have primary key option) and I still get the same error.
'Service2020.ProductsLU' does not contain a property with the name 'vBrandsTypes'.
The primary key would be in the View (vBrandsTypes) and the foreign key in the ProductsLU table.
I've attached a picture of how I did it.
Thanks so much for your help.
ScreenShotViewTable.png
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 34974339
Hi Sheritlw;

I took the same steps I put in the procedure above and the image below shows the results.

OR/M of Northwind DB with Table & View
Also please not the direction of the association. If it is still not working what version of Visual Studio are you using?

Fernando
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 34974353
Pleas note that the Properties panel has a Primary Key property and is set to True.
0
 

Author Comment

by:Sheritlw
ID: 34975131
Hi Fernando.

THANK YOU... It works GREAT!  
I didn't select the id to see it's properties, that is why I didn't see Primary Key.

You are great...
Thanks again.
0
 

Author Closing Comment

by:Sheritlw
ID: 34975136
He is great!
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 34975203
Glad to hear that all is working and as always glad I was able to help.  ;=)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question