DCSIMG
Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer? - Shimmy on .NET

Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

It was several times that I faced this annoying situation till I decided to handle it myself.

The story is simple.

I am using EF designer to mirror the database tables into a .NET DAL.
In the database there is a view that reflects a table or returns a table with additional information I want to keep separated from the table.

I do want to be able to navigate from the table to the view in a short way:

      Dim table = context.Items.FirstOrDefault
      table.TableViewReference.Load()
      Dim view = table.View
To be able to set relationships between tables in EF, you manually have to apply several changes to the .edmx file.
The bad news, is that once you click "Update Model From Database" and regenerate your model, all your changes are gone and you have to modify the edmx file once again.
I tried few ways thru the designer but I haven't come along to something satisfactory.
So I developed my own extension to the designer that does the job (processes the view keys) for you.
You then only have to add relationships and referencial constraints and you're set!
If you ever encoutered this issue before, go ahead and install this extension: http://visualstudiogallery.msdn.microsoft.com/en-us/d9b76b5d-d45c-4e79-8d28-31444be582de.
I also posted a connection to Microsoft, I hope them to implement this out-the-box and improve the functionality for views and relationships between them.
I don't really count on it for upcoming version, from what I spoke to a few MS employees we'll still have to wait, it's not implemented in the CTP4 either.
Don't forget to rate, comment, etc. etc. blah blah blah
Published Friday, September 03, 2010 4:17 AM by Shimmy

Comments

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Tuesday, October 12, 2010 2:47 PM by Edwin

I have been looking for something like this. Thanks Shimmy! Is this edmx extension suppossed to remove the views 1) DefiningQuery and the and 2) store:Name and 3) update store:Schema=".." to Schema ="" (as described by Mehroz post?) these were reverted back after I did a Datababase refresh.

Would it be possible for you to post the code to update the edmx extension? Thanks!

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Thursday, October 14, 2010 8:40 AM by Shimmy

Please send me a private msg containing your email

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Friday, October 29, 2010 6:44 PM by Oscar Agreda

This is great.

you have solved many issues.

I would really recommend to crate a video on how to install it and what it does, I think that every net developer using EF4 needs your plug in.. but they just don't know this is the plug in that will solve their issues..

But by looking at a video they will understand

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Sunday, October 31, 2010 3:42 AM by Shimmy

Hello Oscar and thanks for your feedback!

I actually think there is nothing to learn about the installation, it should install just like a regular Visual Studio 2010 extension, you just click the download button from the extension gallery and run the file. Windows automatically associates this file with Visual Studio 2010 and it's installed.

If you have any other issues, please comment and I will do best to help.

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Wednesday, March 16, 2011 11:19 PM by Eric

I must've missed something...  I installed this plug-in via Extension Manager in VS2010 Ultimate. Updated the model from database...

Now getting "Message 6 The table/view 'XXXXXX' does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.

   So I am back to manually editing XML.

   Is that how this is supposed to work, I thought this plug-in alleviates this pain?

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Thursday, March 31, 2011 5:26 AM by Shimmy

Try to save & close the EDM or rebuild your project, it should help.

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Thursday, June 02, 2011 12:22 AM by sip

I don't understand how this extension is supposed to be working :-( I don't have a view in my database, but have a "virtual" view in my edmx defined by <DefiningQuery> tag. It's not preserved during "Update model from database". Should this case to be covered by your extension?

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Thursday, June 02, 2011 3:10 AM by Shimmy

I am not so sure about your particular case, I believe it's not :(

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Thursday, June 02, 2011 3:49 AM by sip

Could you please add this functionality, i.e. support for "virtual" views without real database views to your extension? I really tired to support them manually after each update from database.

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Thursday, June 02, 2011 3:54 AM by Shimmy

I am affraid it's gonna take a long time till I find space to do it. Please don't count on me.

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Thursday, June 02, 2011 4:27 AM by sip

Thanks. One more question. Is it possible to get source code of your extension? I can try to add "virtual" views support by myself.

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Thursday, June 02, 2011 5:02 AM by Shimmy

Can you please explain me more about what your're trying to achieve?

Please be specific about how the edmx should be generated instead of what it's now, and how we can identify it.

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Thursday, June 02, 2011 5:28 AM by sip

Example from my edmx:

<EntitySet Name="AGENCY_CALC_FIELDS" EntityType="Model.Store.AGENCY_CALC_FIELDS" store:Type="Views" store:Schema="SW_MAIN_DEV" store:Name="AGENCY_CALC_FIELDS">

           <DefiningQuery>

           select

 T.AGENCY_ID,

 (Substr(MST_COMMON.AgencyIDMainPhone(t.AGENCY_ID),1,30)) PHONE_MAIN_NUMBER,

 (Substr(MST_COMMON.AgencyIDFax(t.AGENCY_ID),1,30)) FAX_NUMBER,

 (Substr(MST_COMMON.AgencyIDMainAddress(t.agency_id),1,255)) AGENCY_ADDRESS,

 (Substr(MST_Common.MayChangeAgencyCurrency(t.AGENCY_ID),1,1)) ALLOWCHANGECURRENCY

from  AGENCY t

           </DefiningQuery>

         </EntitySet>

There is no AGENCY_CALC_FIELDS view in database, so this view is "virtual" and defined directly in my edmx. And it's assotiated as 1:1 with my AGENCY table, for getting navigation property on AGENCY entity.

If you need more information, just let me know.

# re: Frustrated by lack of support for SQL-Views in ADO.NET Entity-Framework Designer?

Friday, June 03, 2011 1:28 AM by Shimmy

Yes, I need more information.

Please let me know how you'd like your edmx to look, what changes should I apply to it.

Also specify dynamically what I have to change to what.

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above:
Powered by Community Server (Commercial Edition), by Telligent Systems