Solved

LINQ to SQL add ScaffoldColumn attribute

Posted on 2011-03-06
7
984 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

810 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