2

I would like to create a CodeFluent Entities snippet with some linq query inside:

return BaseList.Where(cd => cd.StartDate <= DateTime.UtcNow && cd.EndDate > DateTime.UtcNow)
    .OrderByDescending(cd => cd.Rate)
    .FirstOrDefault();

After building the model I have a compilation error because I'm lacking some using:

using System;
using System.Linq;

in the generated file.

Is there a way to add them ?

Thomas Ledan
  • 118
  • 11

3 Answers3

2

You can add namespace imports in generated code using the BOM producer properties:

  • double click on the producer node in Visual Studio's Solution Explorer
  • select the "Advanced" property grid tab
  • Add "System" and "System.Linq" as namespace imports (separated by a comma)

CodeFluent Entities BOM Producer Advanced Properties

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
1

The Business Object Model (BOM) Producer allows to define additional imports.

  • Open the BOM configuration
  • Go to advanced Tab
  • Set Namespace Imports property to, for example, System.Linq, MyCustomNamespace

The producer will output these usings.

Imports MyCustomNamespace
Imports System.Linq

using System.Linq;
using MyCustomNamespace;
meziantou
  • 20,589
  • 7
  • 64
  • 83
0

Concerning the System namespace, I've found the solution quite easily: just add the namespace before the type name.

return BaseList.Where(cd => cd.StartDate <= System.DateTime.UtcNow && cd.EndDate > System.DateTime.UtcNow)
    .OrderByDescending(cd => cd.Rate)
    .FirstOrDefault();

What about the extensions method ?

Thomas Ledan
  • 118
  • 11