我正在尝试使用接口实现我的persitent类。我创建了以下

public interface IFoo
{
    int Id {get;set;}
}

public class Foo : IFoo
{
    private int _id;

    public int Id {get{return _id;} set{_id = value;}}
}

public interface IBar
{
    int Id {get;set;}
    IFoo Foo {get;set;}
}

public class Bar : IBar
{
    private int _id;
    private IFoo _foo;

    public int Id {get{return _id;} set{_id = value;}}
    public IFoo Foo {get{return _foo;} set{_foo = value;}}
}

是否可以指出Foo是一个有效的类并默认使用它,我不想使用数据库来存储类类型。

由于

罗汉

有帮助吗?

解决方案 3

阅读Telerik指南后,我在他们的论坛上发布了一个问题......

使用接口而不将类型存储在数据库

看起来不可能。

其他提示

descriminator列始终是必需的,因为OpenAccess以后不知道是否有更多有效的实现。你可以做的是使用直接Foo引用作为私有字段并将其公开为Interface属性。 setter中的类强制转换异常可能有助于您找到设置了错误对象的位置。

希望有所帮助,

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top