Blog - comments

I wish someone would demonstrate how they generated the graphs - seems to be a well-kept secret

tim carroll
Thank you for the very informative post. I've been researching why our DB generates so much redo at...
Gary F.

Hi Arnaud,

Can I hav english version of these document.

Rgds

Raffi

Mohammed Raffi
You may check also Valentina Studio 5.x: http://www.valentina-db.com/valentina-studio-overviewit ...
ahmad
Thanks a lot Pierre. This covers everything that would be necessary to upgrade the Enterprise Manage...
Seth with Firebox
Blog Stéphane Savorgnano SQL Server View problem in LightSwitch 2012

dbi services Blog

Welcome to the dbi services Blog! This blog focuses on IT infrastructure - featuring news, troubleshooting, and tips & tricks. It covers database, middleware, and OS technologies such as Oracle, Microsoft SQL Server, Documentum, MySQL, PostgreSQL, Sybase, Unix/Linux, etc. The dbi services blog represents the view of our consultants, not necessarily that of dbi services. Feel free to comment on the postings!

  • Home
    Home This is where you can find all the blog posts throughout the site.
  • Categories
    Categories Displays a list of categories from this blog.
  • Tags
    Tags Displays a list of tags that has been used in the blog.
  • Bloggers
    Bloggers Search for your favorite blogger from this site.

SQL Server View problem in LightSwitch 2012

I recently faced a problem in Visual Studio LightSwitch 2012 with SQL Server views. I attached an external datasource to my project and when I tried to import my view (which is very simple) I experienced some issues.

Here is my View in SQL Server 2012:

During the import process a warning says  my view doesn't have any primary key (apparently it's mandatory in LightSwitch) and that a key has been inferred...

When I check my view in my LightSwitch data source...

...one of my field(rating_id_session) has been changed to a key which means that I will not be able anymore to view all lines of my views in a grid but just one record per session id, which is just impossible for me...

To avoid this issue, we have to find a workaround which needs two steps:

The first one is to avoid that our field rating_id_session becomes a key during the import. For that we will force SQL Server to mark it as "nullable" by converting it.

If you now try to re-import your view, you will have the following error:

All fields are nullable now, so there is no way to create an inferred key: the view is also simply not imported.

We now have to create a dummy primary key to be able to import our view and to see all records.

The best way to create this primary key - which could be unique for each record - is to use NewID().

I will also use the function ISNULL to add my new field to the inferred key.

With this new key, my view is now imported and I will be able to use it correctly.

To resume

When you want to take out a field from an inferred key, you can use CAST or CONVERT functions.

To add a field to an inferred key, use the ISNULL function with 0 for integer fields and N'' for char fields.

And if you don't have one or more fields to use for keys, you have the possibility to use NEWID() to create one.

Hope this will help you ;-)

Rate this blog entry:
1

Stéphane Savorgnano is Consultant at dbi services. He has more than fifteen years of experience in Microsoft software development and in SQL Server database solutions. He is specialized in SQL Server installation, performance analysis, best practices, etc. Stéphane Savorgnano is Microsoft Certified Technology Specialist (MCTS) and Microsoft Certified IT Professional (MCITP) for SQL Server implementation and maintenance. Prior to joining dbi services, he was software engineer at Ciba Specialty Chemicals in Basel. Stéphane Savorgnano holds a Master of Informatics from Mulhouse University (F). His branch-related experience covers Banking / Financial Services, Chemicals & Pharmaceuticals, etc.

Comments

  • No comments made yet. Be the first to submit a comment

Leave your comment

Guest Friday, 24 May 2013
AddThis Social Bookmark Button