1

Scenario: I need to create a report in which the data does not map well to existing entities.

Solution: My solution is to write a raw method and have it return a DataSet.

Assumption: If I write a raw method in which none of the fields in the query match the properties of the entity, it will still work as long as I specify a return type of System.Data.DataSet.

Questions:

  1. Is my assumption correct?
  2. Using the Modeler, other than specifying the Return Type Name as System.Data.DataSet is there anything else I'm suppose to do?
  3. Do you see any errors in my code. I did a build on the model it generated the code without error. But when I build/compile the BOM, that when I get errors. I had to enter my code/xml as a code snippet because stackexchange is being quirky and was the only way it would display. Run code snipper button won't do anything.

  <cf:entity name="Test1" namespace="Amikids.TimeTracking" categoryPath="/Amikids.TimeTracking">
    <cf:property name="Id" key="true" />
    <cf:property name="Name" />
    <cf:instance>
      <cf:instanceValue name="Id">bda62961-eef9-48bd-977e-00732ce36c66</cf:instanceValue>
      <cf:instanceValue name="Name">Mike</cf:instanceValue>
    </cf:instance>
    <cf:instance>
      <cf:instanceValue name="Id">3378eddd-cd46-40e3-b5c5-eecaa1477229</cf:instanceValue>
      <cf:instanceValue name="Name">Joe</cf:instanceValue>
    </cf:instance>
    <cf:method name="LoadReport" body="LOAD() ORDER BY Name" returnTypeName="System.Data.DataSet" />
  </cf:entity>

Errors:

Error 26 'System.Data.DataSet' does not contain a definition for 'LoadReport' and no extension method 'LoadReport' accepting a first argument of type 'System.Data.DataSet' could be found (are you missing a using directive or an assembly reference?)

Error 25 'System.Data.DataSet' does not contain a definition for 'PageDataLoadReport' C:\Projects2\Amikids.TimeTracking\Amikids.TimeTracking\Test1Collection.cs

Error 27 'System.Data.DataSet' does not contain a definition for 'PageLoadReport' C:\Projects2\Amikids.TimeTracking\Amikids.TimeTracking\Test1Collection.cs

Additional Comments:

I looked at the article https://blog.codefluententities.com/2011/06/22/dataset-support-in-codefluent-entities/ but I think it's outdated or incomplete. Below is the syntax from the article and it's very different from what the modeler creates. I attempted to use the same syntax as the article but Codefluent Entities automatically re-wrote in a different way that also didn't work.The method also doesn't indicate if its using SQL Server, Oracle etc so I think some things are missing from the sample.

<cf:method name="LoadAllCities" body="raw" returnTypeName="System.Data.DataSet">
SELECT $Address::City$ FROM $Address$
</cf:method>
Dave
  • 649
  • 5
  • 13

1 Answers1

0

If you want to create a method that returns a DataSet, you have to create a RAW method and set the return type to System.Data.DataSet in the property grid:

<cf:method name="Custom" returnTypeName="System.Data.DataSet">
  <cf:body text="RAW" rawText="SELECT $Customer{Columns}$ FROM $Customer$" language="tsql" />
</cf:method>

However, it may be more practical to use a strongly-typed collection. You can create a lightweight entity and a raw method:

<CityAddress lightweight="true">
  <CityName persistentName="Address_CityName" />

  <cf:method name="LoadAllCities" body="load() raw">
    SELECT $Address::CityName$ FROM $Address$
  </cf:method>
</CityAddress>

Another solution is to use a view: https://blog.codefluententities.com/2014/04/22/views-auto-lightweight-and-the-modeler/

The syntax from the blog post is valid, but the modeler always write the full syntax which may be more verbose.

meziantou
  • 20,589
  • 7
  • 64
  • 83
  • Thanks, I find the lightweight entity makes the most sense in my situation. The reason being is that not only does the report data not map well to the properties of the entities but the reports themselves don't really tie well to any individual entity. Therefore I created a namespace called reports and that's where I put all the lightweight report entities. – Dave Oct 14 '16 at 14:19