Extending SQL LINQ Table Class

M

Mark Olbert

I am trying to extend a table entity class (generated from the visual designer for data contexts) with a property that has no
corresponding column in the underlying Sql Server table.

When I do this, I get a NotSupportedException complaining that the property I added has no supported translation to the database.

The documentation implies that properties not marked with the Column attribute will be ignored when interfacing to the
database...but that's not what appears to be happening.

Is there some other attribute I need to decorate the property with to have the property "skipped"? Or is it just not possible to add
properties to table entity classes using partial classes? If that's the case, the documentation should make that clear.

- Mark
 
S

Steven Cheng[MSFT]

Hi Mark,

I think custom properites with partial class for LINQ object class is
supported. As for the property you added, did you by any chance used it in
any data query expression? It seems the custom property will not be
recognized in any query expression to the datasource. Or you just get the
compile error without using the property in any place? here is a web forum
thread mentioned something about add custom property:

#Custom properties in LINQ to SQL classes
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1656614&SiteID=1

and here is a blog article about extending LINQ to SQL query:

#LINQ to SQL (Part 8 - Executing Custom SQL Expressions)
http://weblogs.asp.net/scottgu/archive/2007/08/27/linq-to-sql-part-8-executi
ng-custom-sql-expressions.aspx

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: Mark Olbert <[email protected]>
Newsgroups: microsoft.public.dotnet.framework
Subject: Extending SQL LINQ Table Class
Date: Sun, 06 Jan 2008 17:37:00 -0800
I am trying to extend a table entity class (generated from the visual
designer for data contexts) with a property that has no
corresponding column in the underlying Sql Server table.

When I do this, I get a NotSupportedException complaining that the
property I added has no supported translation to the database.
The documentation implies that properties not marked with the Column
attribute will be ignored when interfacing to the
database...but that's not what appears to be happening.

Is there some other attribute I need to decorate the property with to have
the property "skipped"? Or is it just not possible to add
properties to table entity classes using partial classes? If that's the
case, the documentation should make that clear.
 
M

Mark Olbert

Steven,

Thanks for the quick reply. You're right, extended properties work fine so long as you don't try to use them in a query.

I think I saw some references on the web to replacing properties that don't map to database fields to method calls which can be used
in queries.

BTW, the second link you gave me doesn't work.

- Mark
 
S

Steven Cheng[MSFT]

Thanks for your reply Mark,

Do you mean the "LINQ to SQL (Part 8 - Executing Custom SQL Expressions) "
link was broken? If so, you can try searching the subject in web directly.
There are a series of LINQ to SQL articles on ScottGu's blog. They are very
helpful.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: Mark Olbert <[email protected]>
Newsgroups: microsoft.public.dotnet.framework
Subject: Re: Extending SQL LINQ Table Class
Date: Mon, 07 Jan 2008 10:33:00 -0800

Steven,

Thanks for the quick reply. You're right, extended properties work fine so
long as you don't try to use them in a query.
I think I saw some references on the web to replacing properties that
don't map to database fields to method calls which can be used
in queries.

BTW, the second link you gave me doesn't work.

- Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top