假设一个这样的表:
| ID| Foo|酒吧|
| --|--|--|
| NUMBER| VARCHAR2| NUMBER|
像这样的类:
public class SomeClass
{
public virtual long Id {get;set;}
public virtual string Foo {get;set;}
public virtual long Bar {get;set;}
}
如何将Bar
Map到Sequence的值?它始终为NULL,尽管插入了其余数据。
我试着根据谷歌搜索:
public SomeTableMapping
{
Schema("ABC");
Table("SomeTable");
// id sequence generator works fine
Id(p => p.Id, map =>
{
map.Column("ID");
map.Generator(Generators.Sequence,
gMap => gMap.Params(new {sequence = "MyID_SEQ"}));
});
Property(p => p.Foo, map => map.Column("FOO");
// This doesn't work, but also doesn't error
Property(p => p.Bar, map => map.Formula("SELECT ABC.Other_SEQ.nextval BAR FROM dual"));
}
更新
如果我将我的Map代码改为这样,它会在我的SomeClass示例上生成Bar
的值,但不会在数据库中的记录上设置:
Property(p => p.Bar, map =>
{
map.Column("BAR");
map.Formula("ABC.Other_SEQ.nextval");
map.Generated(PropertyGeneration.Insert);
}
1条答案
按热度按时间k97glaaz1#
这样就行了