views:

49

answers:

2

HI, I was wondering if any one else had had a problem with VS2010 MVC 2 projects not being able to automaticly create a strongly typed view after doing a fluent mapping?

When trying to do the mapping VS2010 doesnt show the Entities in the drop down and even if i manually put the class in it doent auto build the view .

Cheers Dan

A: 

Have you made your Entity Class Properties public?

The scaffolding engine uses .NET reflection to look at the public properties exposed on the class passed it, and will add appropriate content based on each type it finds

The following works for me:

namespace Entities
{
    public class Page
    {
        public virtual int Id { get; private set; }
        public virtual string Name { get; set; }
        public virtual string Title { get; set; }
        public virtual string Description { get; set; }
    }
}



public class PageMap : ClassMap<Page>
{
    public PageMap()
    {
        Table("Pages");
        Id(x => x.Id);
        Map(x => x.Name);
        Map(x => x.Keywords);
        Map(x => x.Description);

    }
}

Strongly Typed View: ticked

View Data Class: Entities.Page

View Content: List

Which then creates:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Entities.Page>>" %>

<table>
    <tr>
        <th></th>
        <th>
            Id
        </th>
        <th>
            Name
        </th>
        <th>
            Title
        </th>
        <th>
            Description
        </th>
    </tr>

<% foreach (var item in Model) { %>

    <tr>
        <td>
            <%= Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) %> |
            <%= Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ })%> |
            <%= Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })%>
        </td>
        <td>
            <%= Html.Encode(item.Id) %>
        </td>
        <td>
            <%= Html.Encode(item.Name) %>
        </td>
        <td>
            <%= Html.Encode(item.Title) %>
        </td>
        <td>
            <%= Html.Encode(item.Description) %>
        </td>
    </tr>

<% } %>

</table>

<p>
    <%= Html.ActionLink("Create New", "Create") %>
</p>
Nicholas Murray
cheers - It's a bug with VS and NHab 3. Linking to v2 lets it see the classes.
Dreaddan
@Dreaddan - I'm using v2 of course, glad you figured it out!
Nicholas Murray
+1  A: 

It looks like Vs2010 doent like something to do with Nhibinate 3. linking to v2 seems to get it to work as required even when relinking back to v3.

Very odd

Dreaddan