0
votes

I have a Web API 2 service that has a Breeze Controller that connects to entity framework. It gets several EntityTypes from tables in my database (like Employee, UserConfiguration, Shipment etc)

It all works great.

But now I want to make a "custom" EntityType. One called User. I don't actually have a User table in my database. I am using a few different sources to make an instance of User. (Employee Table, UserConfiguration Table and a Service Call)

When I make the call to my GetCurrentUser method, the data is returned correctly to the client.

But I have this setup to allow my constructor to be called when breeze creates the object:

metadataStore.registerEntityTypeCtor('User', Entities.User, this.setupEntity);

But the constructor never gets called.

How can I make it see the User entity?

Note: If possible, I would prefer to set this up in my Web API code, rather than in my JavaScript/TypeScript.

In case it is relevant, here is part of my User class:

[DataContract]
public class User
{
    public User(Employee employee, ApplicationPermission permissions,
                UserConfiguration userConfiguration)
    {
        EmployeeId = employee.EmployeeId;
        LanId = employee.LanId;
        FirstName = employee.FirstName;
        LastName = employee.LastName;
        UserPermissions = new List<UserPermission>();            
        UserConfiguration = userConfiguration;
    }

    [DataMember]
    int? EmployeeId { get; set; }
    [DataMember]
    string FirstName { get; set; }
    [DataMember]
    string LastName { get; set; }
    [DataMember]
    List<UserPermission> UserPermissions { get; set; }
    [DataMember]
    private UserConfiguration UserConfiguration { get; set; }
}
1
I found an old angular project where i remember doing what you are trying to do. This is how that part looked: function addFilterType(metadataStore) { metadataStore.addEntityType({ shortName: "Filter", autoGeneratedKeyType: breeze.AutoGeneratedKeyType.Identity, dataProperties: { id: { .... so apparently i used addEntityType, not register constructor. Have you tried that? - HotTowelie
@HotTowelie - Thanks for looking that up for me. I think that is how you do it in the javascript. I found a way to do it server side. (See my answer below.) - Vaccano

1 Answers

0
votes

I was able to get this to work by adding my custom class to the Entity Framework model (even though it does not have a table). I think it was easier with the a code model. I don't know if it would have been doable with a design model (edmx).

This link got me started:

http://breeze.github.io/doc-js/metadata-with-ef.html