yohan.jayarathna
yohan.jayarathna

Reputation: 3463

linq to sql - renaming column name

How can I rename table column renaming using LINQ like in regular SQL

SELECT t.template_nm as [Template Name]
FROM Template t

I found a answer from the internet, I can rename the column name. But can't have spaces between two words.

var template = from t in db.TEMPLATEs
       select new { Template_Name = t.TEMPLATE_NM };

But I want to rename it without underscore(_) "Template Name"

Pls help

Thank You

Upvotes: 1

Views: 4968

Answers (2)

Ahmed Khalaf
Ahmed Khalaf

Reputation: 1220

You can use DataAnnotations or just make the view detect Camel Notation and add spaces ;)

Upvotes: 3

Mongus Pong
Mongus Pong

Reputation: 11477

Quite simply, you can't. You must give each column a valid c# variable name.

This is used to construct an anonymous class with your given property names. You will need to refer to these later on in code, and so it has to be valid c# code.

Upvotes: 5

Related Questions