关于entityframework codefirst方式继承的问题。

鹏飞001 2013-03-18 04:08:21
abstract entitybase
{
guid id
datetimte createdate
datetime createuser
User modifydate
User modifyuser
}

user:entitybase
{
string name
string gender
}

在entitybasebase中引用user是不是不对啊。我这样写无法生成数据库,提示出错。

...全文
453 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
熊猫无敌 2013-04-02
  • 打赏
  • 举报
回复
楼主这样显然是不对的,首先楼主对面向对象理解可能不够深刻 请问下面向对象中抽象类中含有自己的继承类属性的意义何在呢 如果这个抽象类再有其它的子类例如AdminUser继承它(而没有User子类),抽象类里面的User起什么作用? 虽然不懂楼主的逻辑,举个正确的例子,测试成功,贴上关键代码: public abstract class Shape { public int Id { get; set; } public string Name { get; set; } } public class Square : Shape { public decimal Length { get; set; } } public class Circle : Shape { public decimal Radius { get; set; } } using (var context = new BreakAwayContext()) { var circle = new Circle() { Name = "Circle", Radius = 5.0m }; var square = new Square() { Name = "Square", Length = 9m }; context.Shapes.Add(circle); context.Shapes.Add(square); context.SaveChanges(); }
三五月儿 2013-04-01
  • 打赏
  • 举报
回复
感觉下面的代码有问题吧
datetime createuser
User modifydate
User modifyuser
是不是应该下面这样:
datetime modifydate
User createuser
User modifyuser
菜牛 2013-03-27
  • 打赏
  • 举报
回复
你这个代码本身就有问题啊。
不懂必须要问 2013-03-25
  • 打赏
  • 举报
回复
等等高手,我也有这个问题。
宝_爸 2013-03-25
  • 打赏
  • 举报
回复
我也没有这么用过,当初考认证是明白过,现在又忘了:( lz看看下面的文章吧: http://weblogs.asp.net/manavi/archive/2010/12/24/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tph.aspx 三种方式都看下,再决定用哪种 --Table per Hierarchy (TPH): Enable polymorphism by denormalizing the SQL schema, and utilize a type discriminator column that holds type information. --Table per Type (TPT): Represent "is a" (inheritance) relationships as "has a" (foreign key) relationships. --Table per Concrete class (TPC): Discard polymorphism and inheritance relationships completely from the SQL schema.

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧