楼主这样显然是不对的,首先楼主对面向对象理解可能不够深刻
请问下面向对象中抽象类中含有自己的继承类属性的意义何在呢
如果这个抽象类再有其它的子类例如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();
}