【发布时间】:2015-01-23 05:56:00
【问题描述】:
我被困在棘手的情况下,我在集成 ASP.NET 动态数据 + EF6 时遇到过
我有几张桌子: Products -> ProductSales,映射为1 - MANY
已使用 EF CF 方法创建数据库。
来自 Init 架构的某种代码。
CreateTable(
"dbo.ProductSales",
c => new
{
Id = c.Long(nullable: false, identity: true),
IsActive = c.Boolean(nullable: false),
Price = c.Int(nullable: false),
Description = c.String(),
Name = c.String(nullable: false),
Product_Id = c.Long(),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.Products", t => t.Product_Id)
.Index(t => t.Product_Id);
CreateTable(
"dbo.Products",
c => new
{
Id = c.Long(nullable: false, identity: true),
Description = c.String(),
IsNew = c.Boolean(nullable: false),
Discount = c.Int(nullable: false),
IsActive = c.Boolean(nullable: false),
Name = c.String(nullable: false),
Category_Id = c.Long(nullable: false),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.Categories", t => t.Category_Id, cascadeDelete: true)
.Index(t => t.Category_Id);
DTOS:
public class Product : Entity
{
public string Description { get; set; }
public bool IsNew { get; set; }
public int Discount { get; set; }
[DefaultValue(true)]
public bool IsActive { get; set; }
public virtual ICollection<ProductSale> Sales { get; set; }
[Required]
public virtual Category Category { get; set; }
public virtual ICollection<Photo> PhotoCollection { get; set; }
public virtual ICollection<Shop> Shops { get; set; }
}
public class ProductSale : Entity
{
public bool IsActive { get; set; }
public int Price { get; set; }
public string Description { get; set; }
public virtual ICollection<Photo> PhotoCollection { get; set; }
public virtual Product Product { get; set; }
}
public class Entity
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
}
应用程序大部分工作正常。但有一个烦人的问题。 对于案例 1-MANY,如上所述,DD 将构建“view productsales” 有链接
/ProductSales/List.aspx?Product.Id=1 - 我认为这是不正确的。
我尝试使用 url 并发现 /ProductSales/List.aspx?Id=1 - 它有效。
更新:我遇到了错误:
DataBinding:“System.Web.DynamicData.Util.DictionaryCustomTypeDescriptor”不包含名为“Product”的属性。 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。 异常详细信息:System.Web.HttpException:DataBinding:“System.Web.DynamicData.Util.DictionaryCustomTypeDescriptor”不包含名为“Product”的属性。
我知道我可以去 ChildrenField 模板并使用 ChildrenPath 做一些 hack 魔术,但希望从社区获得甜蜜和清晰的解决方案,提前致谢。
【问题讨论】:
-
我不知道这是否有帮助,但看起来动态数据正在创建一个视图,其顶层是 Prodcut,并且您正在显示该产品的所有 ProductSales。跨度>
标签: c# asp.net entity-framework asp.net-dynamic-data