newman
newman

Reputation: 6911

Breeze Error: Unable to locate a 'Type' by the name: 'xxx'. Be sure to execute a query or call fetchMetadata first

I know the same question has been asked here. However, that answer doesn't solve my problem, because in my project, I don't specify "hasServerMetadata: false". Actually, most of time, I don't get this error.

This error occurs when I try to create a new student (first time okay), and while still in the editing mode, if I click browser's refresh button, I get this error. If I edit an existing student, I don't have this problem.

My project is basically based on Breeze/Angular SPA ToDo template.

Here are some related codes.

Model:

public class Student
{
    public int Id { get; set; }
    public string LastName { get; set; }
    public string FirstName { get; set; }

    [ForeignKey("ContactInfo")]
    public int ContactInfoId { get; set; }
    public ContactInfo ContactInfo { get; set; }
}

public class ContactInfo
{
    public int Id { get; set; }
    public string Street { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string ZipCode { get; set; }
}

datacontext.js:

function createStudent() {
    var student = manager.createEntity("Student", { createdOn: new Date() });
    student.contactInfo = manager.createEntity("ContactInfo");
    student.contactInfo.state = "TX";
    return student;
}

Upvotes: 2

Views: 1812

Answers (1)

sjkp
sjkp

Reputation: 895

According to other posts on the interweb, you have to call

manager.fetchMetadata(); 

before you can create new entities.

Upvotes: 1

Related Questions