Solved

LINQ to SQL add ScaffoldColumn attribute

Posted on 2011-03-06
7
979 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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 2

Author Comment

by:michael1174
Comment Utility
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 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
>>  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
Comment Utility
Thank you very much for the answer & explaination.
0
 
LVL 74

Expert Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now