Solved

LINQ to SQL add ScaffoldColumn attribute

Posted on 2011-03-06
7
987 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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

752 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