Giter VIP home page Giter VIP logo

Comments (5)

jods4 avatar jods4 commented on June 12, 2024

[Expression] or [ExpressionMethod] don't do the trick?

from linq2db.

jogibear9988 avatar jogibear9988 commented on June 12, 2024

With this code, the query works:

public static class CustomFieldsExtension
{
    [Sql.Expression("CustomField1", PreferServerSide = true)]
    public static string cf1_MyCustomerProperty(this WmsLoadCarrierDTO lc) => lc.CustomField1;

    public static void cf1_SetMyCustomerProperty(this WmsLoadCarrierDTO lc, string value) => lc.CustomField1 = value;

    [Sql.Expression("CustomDate1", PreferServerSide = true)]
    public static DateTime? cd1_MyCustomerDate(this InfeedAdviceDTO iv) => iv.CustomDate1;

    public static void cd1_SetMyCustomerDate(this InfeedAdviceDTO iv, DateTime? value) => iv.CustomDate1 = value;
}

but the update in the database does not:

            var table = s.GetTable<WmsLoadCarrierDTO>());
            var u = table.Set(x => x.cf1_MyCustomerProperty(), "test2");
            u.Update();

Should this work? Is it an error that the Expression is not used here?

image image

from linq2db.

jods4 avatar jods4 commented on June 12, 2024

Oh you want to set them also. I did not expect that to work, as [Expression] is an arbitrary string (or arbitrary linq expression) but UPDATE can only set a field, which is a lot more restrictive.

Not sure what you can do if you don't want to declare those as properties on the data class.

Note that the first argument to .Set(p, v) is an Expression, so if you had an extension method that returns such extension it should work. Not the best but could be a workaround:

static Expression<Func<WmsLoadCarrierDto, string>> MyCustomerSetter => dto => dto.CustomField1;

db.GetTable<WmsLoadCarrierDto>()
  .Set(MyCustomerSetter(), () => "ACME")
  .Update();

from linq2db.

sdanyliv avatar sdanyliv commented on June 12, 2024

Better to use ExpressionMethod with Sql.Property

public static class CustomFieldsExtension
{
    [ExpressionMethod(nameof(cf1_MyCustomerPropertyImpl)))]
    public static string cf1_MyCustomerProperty(this WmsLoadCarrierDTO lc) => lc.CustomField1;

    static Expression<Func<WmsLoadCarrierDTO, string>> cf1_MyCustomerPropertyImpl()
        => dto => Sql.Property<string>(dto, nameof(WmsLoadCarrierDTO.CustomField1));

    // other are similar
}

from linq2db.

jogibear9988 avatar jogibear9988 commented on June 12, 2024

works like a charm.

thanks

from linq2db.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.