Reputation:
Normally when a stored procedure is called, we have to set up a model for it. So a basic model would be like this.
Database:
TABLE [dbo].[ExampleWithAccentedLetters](
[Ngay] [DateTime] ,
[Ma_Cttv] [int]
Then my object model is easy and simple to set up with just:
public class DataModel
{
public DateTime Ngay { get; set; }
public int Ma_Cttv { get; set; }
}
But what if a stored procedure returns me a table with a column with accented letters or special characters like this.
TABLE [dbo].[ExampleWithAccentedLetters](
[Ngay] [DateTime] ,
[Ma_Cttv] [int]
[Điện tự phát] [int]
How can I implement my model now?
Upvotes: 0
Views: 179
Reputation: 35037
I think ColumnAttribute could work here:
public class DataModel
{
public DateTime Ngay { get; set; }
public int Ma_Cttv { get; set; }
[Column(Name = "Điện tự phát")]
int Column3 {get; set;}
}
Upvotes: 1
Reputation: 409
I'm assuming you can't just rename the column which would probably easiest solution. You might have to return a view and rename the column in the view. You can create model classes for views like you can for tables.
EDIT
You can create a view and rename it's columns so your c# class can use the new non-accented column name(s) like so:
create view nonAccentedView (Ngay, Ma_Cttv, DienTuPhat)
as
select [Ngay], [Ma_Cttv], [Điện tự phát]
from [dbo].[ExampleWithAccentedLetters]
Now your c# class can look like this when you return the view:
public class NonAccentedView {
public DateTime Ngay { get; set; }
public int Ma_Cttv { get; set; }
public int DienTuPhat { get; set; }
}
Upvotes: 0