Answered by:
Selecting different views using the Entity Framework

Question
-
Hi Guys,
I hope this is the right place for this question. I have an application that I am trying to convert from using a straight ADO.NET to sql server connection and I want to use the Entity Framework. In my app the when the user logs on they are presented with a drop down box of views that are associated with the user's ID number. For example, let's say the following views exists:
- 3050_CUSTOMER_VIEW
- 3050_ORDERS_VIEW
- 3051_CUSTOMER_VIEW
- 3051_ORDERS_VIEW
Once the user selects logs on, they only see the customer view that they are allowed to see. A user with ID number 3050 will only be able to see the 3050 views and a user with the ID 3051 will only be able to see the 3051 views. The underlying views have complex aggregates that are different for each user.
How can I create an Entity Model that can support something like this? I was thinking of using a stored procedure mapped to an entity, but I am not sure how to acheive this.
In my C# app I want to present a drop down box with views that are associcated with a users's ID and the user will be able to select queries that execute against the selected view.
Can someone point me in the right direction?
Thanks,
Stephane
Sunday, January 9, 2011 3:00 PM
Answers
-
Hi MrTouya,
Thanks for your feedback.
In your scenario, I don't recommand you use EF, each View will mapping an entity in EF. I think you the Role table contains userId and ViewName, because the relationship between User table and Views is many to many. You can easy query Role table to get user's Views then access the view, this is my thought.
Have a nice day.
Alan Chen[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Jonathan Aneja -- MSFT Saturday, January 15, 2011 1:13 AM
- Marked as answer by Alan_chen Wednesday, January 19, 2011 6:16 AM
Tuesday, January 11, 2011 2:56 AM
All replies
-
Hi MrTouya,
Welcome to MSDN forums.
I think I got your needs from your description, yeah, stored procedure can realize view mapping, but I don't think it is a good way, you may create a role table to map views to entities.
Another thing is there are many views in your database, if the views' structure are different, I think there is no need to use EF, because the entity is fixed after it was designed. If they are just less than 5 roles, you can create different entities to get views. In your scenario, I think Ado.net is more flexible than EF, thanks.
Have a nice day.
Alan Chen[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, January 10, 2011 8:50 AM -
Hi Alan,
Thanks for your response.
All the views have the same structure. I would like to investigate your suggestion of creating a role table to map to views. Can you give me some direction on how to create a role table map and how to map the views to the entities? It sounds like this could be what I was looking for!?
Thanks Again,
Stephane
Monday, January 10, 2011 1:10 PM -
Hi MrTouya,
Thanks for your feedback.
In your scenario, I don't recommand you use EF, each View will mapping an entity in EF. I think you the Role table contains userId and ViewName, because the relationship between User table and Views is many to many. You can easy query Role table to get user's Views then access the view, this is my thought.
Have a nice day.
Alan Chen[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Jonathan Aneja -- MSFT Saturday, January 15, 2011 1:13 AM
- Marked as answer by Alan_chen Wednesday, January 19, 2011 6:16 AM
Tuesday, January 11, 2011 2:56 AM -
Hi MrTouya,
I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?
If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.Have a nice day.
Alan Chen[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, January 17, 2011 3:41 AM