Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 A quandary (SQL 2008, Views, Geography, LINQ)

Author  Topic 

jtcedinburgh
Starting Member

4 Posts

Posted - 2008-09-24 : 09:57:34
Hi folks.

I'm writing an application which makes use of the location types which are new to SQL 2008. In my case the Geography type.

I have also been asked to explore the use of LINQ To SQL in VS.2008, which has been interesting but in which I've encountered a problem which has a workaround which has another problem which perhaps someone can help me with...

The first problem:
LINQ To SQL in VS.2008 doesn't support the Geography type natively, so I have had to resort to a custom view which splits up my Lat/Long data into supported types. I have used a view as the base table can't be changed without major impact, and so a view is the sensible option.

This allows my LINQ code to work with the data contained within the Geography data type, and all appears to be well.

However, when I now want to use LINQ to add or update data through this view, I get an error which states: "Can't perform Create, Update or Delete operations on 'Table(<myView>)' because it has no primary key."

Absolutely correct, there is no primary key on my view because as I understand it there is no support for this in a view.

Any ideas? I could easily drop back to stored procedures, but as my objective here is to explore the use of LINQ within our project as a replacement for stored procedures (and with the benefits of having a strong mapping between source code and the relational data via the LINQ To SQL auto code), I wanted to see if there is anything else I can try...

Thanks,

John
   

- Advertisement -