Giter VIP home page Giter VIP logo

Comments (3)

evaanp avatar evaanp commented on June 12, 2024 1

Did you find a solution for this? I get this error when serializing an expression with an StringComparison enum in it.

Edit: I found the solution. There is an AddKnownType method in every serializer.

from serialize.linq.

jacodv avatar jacodv commented on June 12, 2024

I have also tried a simple type with the DataContract attribute. But adding the [Datacontract] attribute to all our models are not an option if that was the requirement.

** Simple Type **

[DataContract]
  public class OutputChannelLogTest
  {
    public string CreatedBy { get; set; }
    public string Channel { get; set; }
  }

Updated Test

[Test]
    public void CreateQuery_GivenExpression_ShouldGenerateReport()
    {
      // arrange
      Setup();
      var emptyList = new List<OutputChannelLogTest>().AsQueryable();
      var query = emptyList.Where(x => x.Channel == "Email");
      var expression = query.Expression;
      var settings = new FactorySettings(){UseRelaxedTypeNames = true};
      var expressionSerializer = new ExpressionSerializer(new JsonSerializer(), settings);
      var expressionText = expressionSerializer.SerializeText(expression);

      Console.WriteLine(@$"Expression: {expression}");
      Console.WriteLine(@$"ExpressionText: {expressionText}");

      var dbItems = Builder<OutputChannelLogTest>
        .CreateListOfSize(4)
        .TheFirst(2)
        .With(x => x.Channel = "Sms")
        .TheNext(2)
        .With(x => x.Channel = "Email")
        .Build();
      var dbQuery = dbItems.AsQueryable();


      // action
      var reportItems = dbQuery.Provider.CreateQuery<OutputChannelLogTest>(
        expressionSerializer.DeserializeText(expressionText));

      // assert
      reportItems.Count().Should().Be(2);
    }

from serialize.linq.

jacodv avatar jacodv commented on June 12, 2024

I did not. I reverted to getting the actual query from the provider, in my case MongoDB. Then I recreate the IQueryable from the actual query and work with the result.

Look at Remote.Linq. I came close to solving the problem with that package, but still not all the permutations.

from serialize.linq.

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.