linq2db / linq2db.EntityFrameworkCore

Bring power of Linq To DB to Entity Framework Core projects
MIT License
462 stars 38 forks source link

Hidden dependency to Microsoft.SqlServer.Types in .Net core 5 project #127

Closed LadislavSopko closed 3 years ago

LadislavSopko commented 3 years ago

construction Update expression I got

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.SqlServer.Types, Culture=neutral, PublicKeyToken=null'.

at row :

upd = table.Set(CreateExpression(pr), pr.GetValue(entity));

public Expression<Func<ET, object>> CreateExpression(PropertyInfo property)
        {
            var type = typeof(ET);
            var parameter = Expression.Parameter(type);
            var access = Expression.Property(parameter, property);
            var convert = Expression.Convert(access, typeof(object));
            var function = Expression.Lambda<Func<ET, object>>(convert, parameter);
            return function;
        }

public void Update(ET entity)
        {

            var key = _keyProperty.GetValue(entity);

            var e2 = DynamicExpressionParser.ParseLambda<ET, bool>(new ParsingConfig(), true, $"c => c.{_KeyField} == {key}");

            var table = db.Set<ET>().Where(e2);

            IUpdatable<ET> upd = default;

            foreach (var pr in _et.GetProperties())
            {
                if (pr.Name != _KeyField)
                {
                    if (upd == default)
                    {
                        upd = table.Set(CreateExpression(pr), pr.GetValue(entity));
                    }
                    else
                    {
                        upd = upd.Set(CreateExpression(pr), pr.GetValue(entity));
                    }
                }
            }

            upd.Update();

        }

thx.

LadislavSopko commented 3 years ago

Original MS nuget is not compatible with .Net Core but it can be replaced with: dotMorten.Microsoft.SqlServer.Types then it work.