views:

320

answers:

1

I'm currently working on a Silverlight application connected to a SQL Server 2008 Express database that is largely based on a demo on Brad Abrams' blog. (NOTE: The demo file at the specified link is actually a different solution that the one he shows on the live running application. The demo in the blog post uses Entity Framework, while the live application uses POCO).

I am trying to figure out why Entity framework is returning a fixed width string for fields that are set up as nvarchar(MAX). (By "Fixed Width," I mean something like "DC ", where there's white space at the end of the content of the string).

In the demo file, which is connected to an included MDF file, the Name field is a nvarchar(max) field, and entity framework correctly returns the trimmed string. However, in my personal application, which is connected to a SQLEXPRESS database, a nvarchar(max) field is still returned with the white space at the end, fixed width, and untrimmed. When I hover over the return this._itemPrefix; line of Entity Model C# file at runtime, it shows the item with the white space, untrimmed. I can't figure out why it works in his demo but not in my file.

Is there something I can do other than alter the code in the entityModel.Designer.cs to have it return a trimmed string? Has anyone else ran into this issue?

+2  A: 

How many spaces? The only reason I can think of, is because you stored the string that way.
Working as intended.

You should trim your strings with Trim() or TrimEnd() before you store them if you're using Entity Framework.

Thorarin
I didn't think to run RTrim() on all of my values in the SQL Server database table. I had changed their field from nchar to nvarchar, but I didn't think to check to see if the values were still padded.Sure enough, when I updated those fields with RTRIM on the server, everything worked great in Entity Framework. Thanks for your help!
Ben McCormack