无法使用 Fluent Nhibinate 和 MVC2 在 VS2010 中创建强类型视图

发布于 2024-09-24 17:15:14 字数 137 浏览 3 评论 0 原文

你好, 我想知道是否还有其他人遇到过 VS2010 MVC 2 项目在进行流畅映射后无法自动创建强类型视图的问题?

当尝试进行映射时,VS2010 不会在下拉列表中显示实体,即使我手动将类放入其中,也不会自动构建视图。

干杯 担

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假面具 2024-10-01 17:15:14

看起来 Vs2010 不喜欢与 Nhibinate 3 有关的东西。链接到 v2 似乎可以让它按要求工作,即使重新链接回 v3 也是如此。

很奇怪

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

岁吢 2024-10-01 17:15:14

您是否公开了实体类属性?

脚手架引擎使用 .NET 反射来查看传递给它的类上公开的公共属性,并根据它的每种类型添加适当的内容 finds

以下内容对我有用:

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);

    }
}

强类型视图:勾选

查看数据类:Entities.Page

查看内容:列表

然后创建:

<%@ 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文