我想知道我是否可以在我的项目 (asp.net mvc 4 c#) 中使用类似 mongodb 的模型(模型类)。
例如:
namespace Demo.Models
{
public class Model1
{
public int ID { get; set; }
public string Title { get; set; }
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
public class MovieDBContext : DbContext
{
public DbSet<Model1> models { get; set; }
}
}
假设这是 mssql 数据库的标准模型。我可以创建这样的模型来使用 MongoDB 集合、文档吗? 如果是,如何? (如果你能给我提供一些例子的链接)。
谢谢。
最佳答案
是的,你不能忘记添加 BsonId 属性,因为每个对象都必须有自己唯一的 ID。
public class Model1
{
[BsonId]
public int ID { get; set; }
public string Title { get; set; }
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
你可以在这里找到例子:
http://www.joe-stevens.com/2011/10/02/a-mongodb-tutorial-using-c-and-asp-net-mvc/
关于c# - asp.net c# 和 mongodb 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12167515/