本文介绍了HOWTO指定表名与实体框架代码优先流利的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个实体,我配置实体框架把它映射到具有不同名称的数据库表。I have an Entity and I am to configure Entity Framework to map it to a database table with different name.我可以很容易地做到这一点的 代码首先DataAnnotations ( DataAnnotations.Schema.TableAttribute )I can easily do this with Code First DataAnnotations (DataAnnotations.Schema.TableAttribute).但由于限制,现在我不得不使用的代码首先流利的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 这篇关于HOWTO指定表名与实体框架代码优先流利的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-15 14:23