I was able to solve the problem (a general solution using refactoring). But faced with other constraint in SQL CE when using with "IsMaxLength" extension method:
field type ntext cannot be used in WHERE, HAVING, GROUP BY, ON, or IN clauses. This makes it impossible to use NTEXT to overcome the limitation of 4000 characters for string fields.
But I will post here my solution, maybe in the future it will work.
First I added public function to NopEntityTypeConfiguration class:
/// <summary>
/// Configures all string properies (in addition to those fields for which clearly defined maximum length)
/// to allow the maximum length supported by the database provider
/// </summary>
public virtual void SetStringMaxLength()
{
//get ignorable properties
var filterConf = this.GetType().GetProperty("Configuration", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
var filter = filterConf.GetType().GetProperty("IgnoredProperties", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(filterConf) as IEnumerable<PropertyInfo>;
var ignoredProperties = filter != null ? filter.Select(p => p.Name).ToList() : new List<string>();
var names = typeof(T).GetProperties()
.Where(p => p.PropertyType == typeof(string))
.Where(p=>!ignoredProperties.Contains(p.Name))
.Select(p => p.Name).ToArray();
var expression = names.Select(name => Core.DynamicExpression.ParseLambda<T, string>(name, null));
foreach (var expr in expression)
{
var prop = this.Property(expr);
var temp = prop
.GetType()
.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(p => p.Name == "Configuration");
if (temp == null)
continue;
var obj = temp.GetValue(prop);
var maxLength = obj.GetType().GetRuntimeProperty("MaxLength").GetValue(obj);
if (maxLength == null)
//uses ntext in sqlcompact, NVARCHAR(MAX) in SQL Server
Property(expr).IsMaxLength();
}
}
Then I added code to NopObjectContext.OnModelCreating in line 46:
//use this approach to determine the Sql CE is not necessary, may have a better solution.
var dataProviderInstance = EngineContext.Current.Resolve<BaseDataProviderManager>().LoadDataProvider() as SqlCeDataProvider;
if (dataProviderInstance != null)
configurationInstance.SetStringMaxLength();
The file with the changes is attached to this work item details (
see my comment)