Support for mapping functions

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
strandedpirate
Posts: 21
Joined: Tue 07 Jan 2014 12:38

Support for mapping functions

Post by strandedpirate » Thu 09 Apr 2015 09:24

In ED 5.7.576.0 I get the message "Cannot create method for a storage function 'xxx' that can be composed. Only stored procedures may be mapped." when I right click a function and select "Create Method". Not sure why its saying this. It currently adds the correct details for my functions to the .ssdl and all that is missing is for ED to spit out something like the following in the database context template.

Code: Select all

	[DbFunction("MyContext.Data.Models.Store", "fnGetPostPageNumber")]
	public static int fnGetPostPageNumber(int postId, int pageSize)
	{
		throw new NotSupportedException("Direct calls are not supported.");
	}
Is there any technical reason function mapping cannot be done?

This is for Linq to Entities with SQL Server 2014.

Shalex
Site Admin
Posts: 8240
Joined: Thu 14 Aug 2008 12:44

Re: Support for mapping functions

Post by Shalex » Thu 09 Apr 2015 15:15

strandedpirate wrote:I get the message "Cannot create method for a storage function 'xxx' that can be composed. Only stored procedures may be mapped." when I right click a function and select "Create Method". Not sure why its saying this.
Please select your function in Model Explorer > *.Store > Stored Procedures and set its Concealed Function property to True. After this, Entity Framework considers this function will be treated as a stored procedure which does not return a value.

If this information doesn't help, specify your current template(s) and its non-default settings.

strandedpirate
Posts: 21
Joined: Tue 07 Jan 2014 12:38

Re: Support for mapping functions

Post by strandedpirate » Thu 09 Apr 2015 23:34

That would defeat the purpose of a function returning a value. I think there is a disconnect so scratch my first post. It looks like at the moment the concept of custom database functions and model-defined functions doesn't exist in ED.

Can we get Entity Developer to support Custom Database Functions and Model-Defined functions?

https://msdn.microsoft.com/en-us/librar ... 00%29.aspx
https://msdn.microsoft.com/en-us/librar ... 00%29.aspx

This allows us to use custom database functions in linq to entities queries like this:

Code: Select all

var pagesSize = 15;
var flags = ServiceManager.Context.PostFlags
	.OrderBy(a => a.IsHandled)
	.Select(a => new PostFlagModel()
	{
		PostId = a.PostId,
		PostFlagReasonId = a.PostFlagReasonId,
		PageNumber = MyContext.fnGetPostPageNumber(a.PostId, pageSize) // custom database function
	})
	.ToList();

Code: Select all

CREATE FUNCTION [dbo].[fnGetPostPageNumber] 
(
	@postId int,
	@pageSize int
)
RETURNS int
AS
BEGIN
	DECLARE @Result int
	
	-- various logic

	return @Result
END

Shalex
Site Admin
Posts: 8240
Joined: Thu 14 Aug 2008 12:44

Re: Support for mapping functions

Post by Shalex » Mon 20 Apr 2015 15:07

strandedpirate wrote:Can we get Entity Developer to support [...] Model-Defined functions?
https://msdn.microsoft.com/en-us/librar ... 00%29.aspx
Please refer to http://blog.devart.com/model-defined-fu ... loper.html.
strandedpirate wrote:Can we get Entity Developer to support Custom Database Functions [...]?
https://msdn.microsoft.com/en-us/librar ... 00%29.aspx
We will investigate the question and notify you about the result.
strandedpirate wrote:It currently adds the correct details for my functions to the .ssdl and all that is missing is for ED to spit out something like the following in the database context template.

Code: Select all

   [DbFunction("MyContext.Data.Models.Store", "fnGetPostPageNumber")]
   public static int fnGetPostPageNumber(int postId, int pageSize)
   {
      throw new NotSupportedException("Direct calls are not supported.");
   }
As a temporary workaround, please leave the function in SSDL part of the model and add manually the method in a partial class so that your method is not being regenerated by the designer.

Shalex
Site Admin
Posts: 8240
Joined: Thu 14 Aug 2008 12:44

Re: Support for mapping functions

Post by Shalex » Thu 06 Oct 2016 15:56

Shalex wrote:
strandedpirate wrote:Can we get Entity Developer to support Custom Database Functions [...]?
https://msdn.microsoft.com/en-us/librar ... 00%29.aspx
We will investigate the question and notify you about the result.
The generation of static methods by the EntityObject template is supported via the new property Direct Call of EntityMethod in the new build: viewtopic.php?f=32&t=34376.

Post Reply