Solved

LINQ to SQL add ScaffoldColumn attribute

Posted on 2011-03-06
7
985 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
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

828 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