忽略Dapper中的属性 [英] Ignoring properties in Dapper
问题描述
在Dapper中( http://code.google.com/p/dapper -dot-net / ),是否可以忽略模型类中的属性,即使用 Insert
扩展方法时的方法?
我的模型类具有一组已计算的属性,这些属性未保留在关联表中。
In Dapper (http://code.google.com/p/dapper-dot-net/), is there a way to ignore properties in the model class, namely when using the Insert
extension method?
My model class has a set of computed properties which are not persisted in the associated table.
推荐答案
好吧,Dapper没有 Insert
扩展方法,即在dapper.contrib,dapper扩展名或dapper rainbow中。
Well, Dapper has no Insert
extension method, that is in dapper.contrib, dapper extensions or dapper rainbow.
Dapper本身允许您执行以下操作:
Dapper itself allows you to do:
Animal a = new Animal {Age = 10, Family = "Canine"}
// only insert Age
cnn.Execute("insert Animal(Age) values (@Age)", a);
要解决某些扩展类,有时可以执行以下操作:
To work around for some of the extension classes you can sometimes do:
cnn.InsertExtension("Animal", new{a.Age});
无论如何,对于复杂的过滤插入,您始终可以退回到原始的Dapper。
Regardless, you can always fall back to raw Dapper for your complex filtered inserts.
这篇关于忽略Dapper中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!