Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Any setting to convert null strings to empty automatical
Message
 
 
À
29/09/2014 12:42:35
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01608410
Message ID:
01608472
Vues:
27
>>>Did I misunderstand your explanation. I thought you said:
>>>(a) SQL database does not allow Null strings ?
>>>(b) You were having a problem trying to save an empty C# string.
>>>If so then ConvertEmptyStringToNull(false) sounds like what you need.
>>
>>Please read my original question carefully again.
>>
>>I'll repeat the situation.
>>
>>1. In our database we have columns which do not allow null values (all data types except dates are not-nullable in our database).
>>
>>2. We're using Reverse POCO generator to generate our data and models and then custom scaffolding templates to generate view models, adapters, repository, angular forms, etc.
>>
>>3. When we add a new row in our form, the string values are NULL unless we put values into them.
>>
>>4. We need to save these NULL values as empty strings.
>>
>>Our original solution was similar to discussed in that thread because the original code was saving strings in upper case. So, there was explicit code in the SaveChanges method that saved null strings as empty.
>>
>>We later decided there is no need for converting all strings to upper case. So, I commented out the call to the conversion. As a result of this that new problem of saving NULL strings as empty strings arrived.
>>
>>We can go back to the solutions suggested in the thread I mentioned by using some code in the SaveChanges method. I think the code in that thread is more efficient than our original.
>>
>>Or, alternatively, we may try to implement getter for the property (it is actually the solution I implemented in a few ViewModels manually).
>>
>>I think getter property sounds like a better idea. I already found the code where we may want to make this plug:
>>
>>
>>Entity = string.Format("public {0}{1} {2} {3}{4}", PropertyType, CheckNullable(this), PropertyNameHumanCase, IsStoreGenerated ? "{ get; internal set; }" : "{ get; set; }", comments);
>>
>>I am also thinking I'll write a request to the author of the Reverse POCO generator to add some extra property and include this getter into new version of his generator.
>
>Sounds like the first suggestion of modifying the code generator might work:
<#+ if (primitiveProperty.TypeUsage.ToString().Split('.').Last() == "String") { #>
>   if (value == null) value = "   ";
>   else value = value.Trim();
><#+ } #>
If value isn't an empty string then it should get back to the DB OK. If you must have an empty string in the DB then set value to an empty string and use in conjunction with the ConvertEmpyStringsToNull(false).
>
>Haven't tried it but it sounds viable.....

Right, I am thinking in that same direction. The only difference is that the tt file is Reverse.POCO tt file and the code there is different.

So, the code I posted is where he generates the get / set accessors (one liners). So, I need to somehow adjust that particular code, I think.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform