I am not a experienced programmer, I need to query the Membership User Collection provided in asp.net mvc.
I want the members be able to add other members as friends, I have created a added friend table.
Id,
MemberId,
Friend_MemberId,
DateAdded
I want to display a list of Members which are not added to this list (like filter already existing friends), but unable to query using linq, can anyone suggest a way, links, articles, would it be better to extend memebership class.
There are quite a number of ways you could go about this.
Let’s examine one.
You can download the working VS2008 solution here. The example is not an MVC project, but the membership provider works the same regardless.
Stipulations:
Create the Friends table in the ASPNETDB:
The following assumes that you are using the default ASPNETDB that is created in app_data. If not, then you have already created and connected to another DB, just take what you need.
Select your project in Solution Explorer, click ‘show all files’ icon at the top of Solution Explorer, expand ‘App_Data’ folder and right-click>Open ASPNETDB.MDF.
In Server Explorer you will see your ASPNETDB.
Project>Add New Item>Text File>Friends.sql
Paste query below. Save.
Right click in editor>Connection>Connect>select ASPNETDB
Right click in editor>Execute SQL
Friends.sql
Add an ADO.Net Entity Data Model to your project and include, at the minimum, the following:
Tables
Views
Query Example:
NOTE: I am by no means a Linq guru. These queries work fine and the generated sql does not seem unreasonable to me, but I am sure there is someone who will have helpful suggestions regarding possible optimizations of the queries.