views:

32

answers:

1

Am trying to call a UDF which just takes a parameter and returns a scalar. The examples I've seen all use a From clause: http://blogs.microsoft.co.il/blogs/gilf/archive/2009/10/20/calling-user-defined-functions-udfs-in-entity-framework.aspx

But I only want to call the UDF, I don't want to "join" it with any entities using a from clause:

  string fieldTag = "TagNameHere";
  var sql = "SELECT XyzModel.Store.FieldNameToFormIdMap(@fieldTag)";
  System.Data.Objects.ObjectQuery<int> query =
    new System.Data.Objects.ObjectQuery<int>(sql, xyzEntitiesContext);
  query.Parameters.Add(new System.Data.Objects.ObjectParameter("fieldTag", fieldTag));

I get the error: "The query syntax is not valid."

This is using .NET 3.5

I could use old style ADO.NET but I'd rather not have to manage another set of connection strings aside from those used for the entity framework.

+1  A: 

Just remove SELECT from your query, like this:
var sql = "XyzModel.Store.FieldNameToFormIdMap(@fieldTag)";

Devart