none
Entity Framework with Sql Compact 4 RRS feed

  • Question

  • Hi,

    it's my first time with EF and SqlCompact

    I have a strange problem, maybe for me that it's my first project with EF..I try to explane

    In a table Product I have a property call ProductName (nChar (50))..when I get this property from, for example by a find by id, I get a string with 50 characters.

    if I put on my report: ProductName = 'Bike' (4 characters)

    I receve by EF : ProductName = 'Bike                ' (50 characters)

    someone know why?

    thanks

     

    Wednesday, June 15, 2011 1:06 PM

Answers

  • Hi Alessio;

    If I understand the question correctly the reason why EF returns, 'Bike ' (50 characters), is that SQL defines nchar as a fixed length string and in your case it is set to 50. When data is stored in this field it is padded with blanks to give a total of 50 characters. When you query this field you will get all 50 characters. Use the Trim method to remove the unwanted spaces.

     


    Fernando

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, June 15, 2011 1:47 PM
  • Use nvarchar(50) instead of nchar(50)


    Please mark as answer, if this was it. Visit my SQL Server Compact blog
    Wednesday, June 15, 2011 3:43 PM

All replies

  • Hi Alessio;

    If I understand the question correctly the reason why EF returns, 'Bike ' (50 characters), is that SQL defines nchar as a fixed length string and in your case it is set to 50. When data is stored in this field it is padded with blanks to give a total of 50 characters. When you query this field you will get all 50 characters. Use the Trim method to remove the unwanted spaces.

     


    Fernando

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Wednesday, June 15, 2011 1:47 PM
  • Use nvarchar(50) instead of nchar(50)


    Please mark as answer, if this was it. Visit my SQL Server Compact blog
    Wednesday, June 15, 2011 3:43 PM