如何使用Entity Framework Code First Fluent API指定表名 [英] How to specify table name with Entity Framework Code First Fluent API

查看:73
本文介绍了如何使用Entity Framework Code First Fluent API指定表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体,我要配置实体框架以将其映射到具有不同名称的数据库表.

I have an Entity and I am to configure Entity Framework to map it to a database table with different name.

我可以使用 代码优先数据注释轻松地做到这一点( DataAnnotations.Schema.TableAttribute ).

I can easily do this with Code First DataAnnotations (DataAnnotations.Schema.TableAttribute).

但是由于现在的限制,我必须使用 代码优先Fluent API (我的域对象将由外部客户端使用,因此它们不应该是特定于技术的-例如,对DataAnnotations有任何引用)

But due to limitations now I have to use Code First Fluent API (my domain objects will be used by external clients, so they shouldn't be technology-specific - e.g. have any references to DataAnnotations)

我在MSDN上进行了搜索,但未找到任何内容.那有可能吗?

I've searched on MSDN but found nothing. So is it possible and how?

谢谢.

推荐答案

您将使用 .ToTable()方法:

modelBuilder.Entity<Department>().ToTable("t_Department");   

来源:MSDN: http://msdn.microsoft.com/en-us/data/jj591617.aspx

这篇关于如何使用Entity Framework Code First Fluent API指定表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆