Fluent Linq to Entities - 无 edmx 文件

发布于 2024-10-03 02:09:20 字数 198 浏览 0 评论 0原文

是否有一个“Fluent Linq To Entites”,我可以使用它来设置我的 dataContext,而无需通过图表文件映射任何内容?

我所需要的只是将我的数据库表映射到某些域类,而不需要延迟加载。 我尝试使用 LinqToSql,但这是不行的,因为我的域类都继承自基类。

注意:我们只能使用.NET 3.5

Is there a "Fluent Linq To Entites" that I can use to Setup my dataContext without having to map anything through diagram files?

All I need is to map my db tables to certain domain classes without any need for Lazy-Loading.
I tried using LinqToSql but it was a No-Go since my domain classes all inherit from base classes.

Note: We can only use .NET 3.5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

来世叙缘 2024-10-10 02:09:20

如果您可以摆脱使用实体框架,您可以使用 Fluent NHibernate + AutoMapping。 http://wiki. Fluentnhibernate.org/Auto_mapping

或者你可以使用 Linq 2 SQL 来装饰你的实体属性。

就像:

[Table(Name="Product")]
public class Product
{
  [Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert]
  internal int Id {get;set;}

  [Column]
  public string Name {get;set;}
}

然后使用 dbcontext 访问它,比如:

ctx.GetTable<Product>().SingleOrDefault(x=>x.Id == 1);

沿着这些线,我把它写在了我的脑海里,但你明白了要点。

我会选择 Fluent+AutoMapping。

If you can get away from using Entity Framework, you could use Fluent NHibernate + AutoMapping. http://wiki.fluentnhibernate.org/Auto_mapping

Or you could use Linq 2 SQL by decorating your entity with attributes.

Like:

[Table(Name="Product")]
public class Product
{
  [Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert]
  internal int Id {get;set;}

  [Column]
  public string Name {get;set;}
}

Then access it using the dbcontext like:

ctx.GetTable<Product>().SingleOrDefault(x=>x.Id == 1);

Along those lines, wrote that off top of my head but you get the gist.

I would go Fluent+AutoMapping.

放肆 2024-10-10 02:09:20

最近有一个 实体框架的 CTP 版本,为“代码优先”或“仅代码”开发风格提供支持。我相信这些库将允许您在没有地图的情况下设置您的上下文。但是,我认为当前发布的实体框架没有任何东西可以满足您的需求。

There has recently been a CTP release of Entity Framework that provides support for a "Code First" or "Code Only" style of development. I believe those libraries will allow you to setup your context without a map. However, I don't think that there is anything currently released for Entity Framework which will do what you're looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文