我正在编写一个asp.net MVC4应用程序。我有几个DAO接口和DTO类,并想将这些类的实例插入到我的mongo数据库中。
我在控制台应用程序中尝试了以下操作,它可以正常工作:
Dynamic.Config.SetKeyName<IInventorySystem>(i => i.Id);
Dynamic.Config.SetIndex<IInventorySystem>("idx_invSystem", false, i => i.Name);
Dynamic.Config.SetKeyName<IContainer>(c => c.Id);
Dynamic.Config.SetIndex<IContainer>("idx_Container", false, i => i.Name);
Dynamic.Config.LoadCollection<IInventorySystem,IContainer>(i=>i.Containers,c=>c.InventorySystemId);
Dynamic.Config.LoadFK<IContainer,IInventorySystem>(c=>c.InventorySystem,c=>c.InventorySystemId);
Dynamic.Configure();
var invSystems = Dynamic.GetCollection<IInventorySystem>();
var containers = Dynamic.GetCollection<IContainer>();
var invSystem = invSystems.New();
invSystem.Name = "bla";
invSystems.Upsert(invSystem);
但是,MVC控制器中的相同代码无法正常工作,我忽略了以下错误:
"Method not found: 'MongoDB.Driver.SafeModeResult MongoDB.Driver.MongoCollection`1.Insert(System.__Canon)'."}
未能进一步隔离问题的方法
实例化DAO并对其属性值进行硬编码,以消除可能是由html表单绑定引起的问题。
使用impromptuInterface生成代理,然后在保存代理之前设置其属性,以消除DTO的问题,请参阅:http : //mongodbdynamic.codeplex.com/documentation
连接到DB Works。创建了集合,但是我无法保存在mvc4应用程序中。
研究
在我的研究中,我发现了许多缺少的方法问题,但都与mongodb.dynamic没有关系。可以找到类似的问题来寻找mongodb c#驱动程序的问题,但这些问题也不尽相同。
为什么选择MongoDB,而不选择关系数据库?因为我想稍后将键值对的字典添加到某个DTO。但是最好先掌握基础知识。
因此,最后感谢您读完本书,对您的任何帮助,或者与mvc兼容的mongo的不同建议,将不胜感激。
版本信息
MongoDb.Dynamic(随nuget一起安装)-版本1.1.1 MongoDb官方C#驱动程序(随nuget一起安装)版本1.10.0
MongoDB.Dynamic大约3年没有更新。这取决于驱动程序的较旧版本。mongocsharpdriver在其1.x系列中未使用semver,因此使用1.10版的驱动程序中没有MongoDB.Dynamic正在使用的方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句