I’m studying ASP.NET MVC and I use LINQ to SQL for model.
I have a table named “Note” with the fields “Title” and “Content”. The “Content” field can contain thousand characters.
What I want to do is to display the LIST of notes in a page. I use table with two columns, for “Title” and SUBSTRING of the “Content” (50 characters). My problem is, I don’t know how to edit the model so that it will display only the substring of the “Content”.
Thanks in advance!
EDIT:
I tried this codes:
List<Note> notes = (from n in databaseModel.Notes
select new Note
{
ID = n.ID,
Title = n.Title,
Content = n.Content.Substring(0,50),
DateCreated = n.DateCreated,
DateModified = n.DateModified
}).ToList();
but gives me error:
Explicit construction of entity type 'domanokz.Models.Note' in query is not allowed.
I created a view of the table with one field truncated. I used the view to create class instead.