I have a situation where I need the LINQ to Entities query to return a substring depending on the length of the string. Here Request:
var query = (
from f in Context.Files
orderby f.DateAdded descending
select new
{
Concerns = f.Concerns.Name,
Sender = f.Sender.Name,
CategoryCount = f.Categories.Count(),
DateAdded = f.DateAdded,
Comment = (f.Comment == null || f.Comment.Length < 5)
? f.Comment : f.Comment
}).Take(10);
So what I do, I get the last 10 added objects of type "Files", and then select a set of properties from it to display inside the list. Some of them are simple strings (Concerns, Sender). CategoryCount returns the number of categories associated with the File object.
However, I want the comment to be truncated if it is longer than the given length. In the above code, everything works correctly. Now when I replace this line:
Comment = (f.Comment == null || f.Comment.Length < 5)
? f.Comment : f.Comment
Using this line:
Comment = (f.Comment == null || f.Comment.Length < 5)
? f.Comment : f.Comment.SubString(0,5)
application throws XamlParseException (???)
"DocumentManager.Views.ListEntriesView", ,
, . SubString LINQ?
, - . , .
EDIT 2 (- , ):
, , :
var query = App.Context.Files.OrderByDescending(File => File.DateAdded).Take(10).AsEnumerable()
.Select(File => new
{
Concerns = File.Concerns.Name,
Sender = File.Sender.Name,
CategoryCount = File.Categories.Count(),
DateAdded = File.DateAdded,
Comment = (File.Comment == null || File.Comment.Length < 100) ? File.Comment : File.Comment.Substring(0, 100) + "..."
});
, SQLite. , , SQLite EF.