Data service using EF - is it possible to use the WebGet method, which returns a custom type?

In my project, I use a Data Service that uses EF. Now I have a custom class that I also want to open through my data service, but I can not get it to work, it seems that it is impossible to mix custom types and EF in a single data service. Any suggestions?

It does not seem to find any information in the metadata.

Error:

The server detected an error processing the request. The exception is the message "Unable to load metadata for the return type" System.Linq.IQueryable 1[ITS.NetProject.Model.CustomEnty]' of method 'System.Linq.IQueryable 1 [ITS.NetProject.Model.CustomEnty] GetCustomEnties () ''. View Server Logs More details. Exception stack trace: ....

Code:

  [ServiceBehavior(IncludeExceptionDetailInFaults=true)] public class ITSServiceOData : DataService<ITSEntities> { public static void InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule("*", EntitySetRights.All); config.SetServiceOperationAccessRule("GetCustomEnties", ServiceOperationRights.AllRead); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; } [WebGet] public IQueryable<CustomEnty> GetCustomEnties() { return from e in this.CurrentDataSource.CustomEnties select e; } } ///Here it is my model definition namespace ITS.NetProject.Model { partial class ITSEntities { public IQueryable<CustomEnty> CustomEnties { get { return ... } } } //Company, Equipment, Owner are EF entity classes [DataServiceKey("Id")] public class CustomEnty { public int Id {get;set;} public Subject Company { get; set; } public Subject Equipment { get; set; } public Subject Owner { get; set; } } } 
+4
source share
2 answers

No, data services do not support this scenario. You can add your own type to your Entity Fx model, but this is far from ideal ...

+1
source

Hmmm Free Racer - Put the class and the object in the model and do it right. According to the recommendation above. - or Make a separate simple model. Use the same connection string.

or for this unpleasant hack ...

 _context.Database.ExecuteSqlCommand(cmdText, parameters); 

when no one is looking at oClock beer. :-)

0
source

Source: https://habr.com/ru/post/1343639/


All Articles