Solved

LINQ to SQL add ScaffoldColumn attribute

Posted on 2011-03-06
7
990 Views
Last Modified: 2012-08-13
Hello,

I am using LINQ to SQL and lets say I have a table called Files.  And in that table, there is a FileID.  I was to give the FileID the attribute of [ScaffoldColumn(false)].

But, my question is, how do I give the FileID that attribute without modifying the linq to sql class file?

I dont want to have to add that attribute everytime i regenerate or make changes to my tables.
0
Comment
Question by:michael1174
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35048084
Partial classes, my friend...  partial classes:
public partial class YouLinq2SqlClass
{
   // Auto generated code
}


[ScaffoldColumn(false)]
public partial class YouLinq2SqlClass
{

}

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35048088
I guess it should be more like:
public partial class YouLinq2SqlClass
{
   // Auto generated code

...

    public int FieldId { get;set; }
}


public partial class YouLinq2SqlClass
{
    [ScaffoldColumn(false)]
    public int FieldId { get;set; }
}

Open in new window

0
 
LVL 2

Author Comment

by:michael1174
ID: 35048112
kaufmed,

Thanks for your input.

would my data context be my class?

 AMCDataContext?

Where exactly do I put the partial class?  Do I create a seperate clas file?

Also did you mean:

[ScaffoldColumn(false)]
public int FileID
}
}
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 2

Author Comment

by:michael1174
ID: 35055270
When I'm on my dbml file, i press F7, it creates a seperate class file:

namespace AMC
{
    partial class AMCDataContext
    {
    }
}

but then when i try to recompile, get a lot of errors....

so i'm just unsure how where to put the partial class....



0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35069153
>>  would my data context be my class?

Whichever class is the class that will have the attribute added to it.

>>  Where exactly do I put the partial class?  Do I create a seperate clas file?

You can if you like; you don't have to. Best practice would have you put in a separate file though, I believe. The name of the file is irrelevant as long as you make the class name the same as the class you are targeting. NOTE both instances of "class" must be marked partial, so if you can't control the definition of the class itself (the original definition), then creating a partial-class add-on will not work.

    http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.80).aspx
0
 
LVL 2

Author Closing Comment

by:michael1174
ID: 35069399
Thank you very much for the answer & explaination.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35071332
NP. Glad to help  = )
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question