实体框架映射问题Concat值 [英] Entity Framework Mapping Question Concat Values

查看:61
本文介绍了实体框架映射问题Concat值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我的情况:



我需要将一个属性映射到两个字段的串联,我不确定应该怎么做。



这是我想要完成的内容的代码示例:



Property AccountSequence = table.PART1 + table.PART2

其中Part1和Part2是varchar



So here is my situation:

I need to map a property to a concatenation of two fields, and I'm not exactly sure how it should be done.

Here's a code sample of what IN THEROY I am trying to accomplish:

Property AccountSequence = table.PART1 + table.PART2
where Part1 and Part2 are varchar

public class MyObjectConfiguration : EntityTypeConfiguration<TemporaryObject>
{
    public MyObjectConfiguration()
    {

        Property(p =>p.AccountSequence).HasColumnName("PART1").HasColumnName("PART2");

推荐答案

我会添加一个部分用于扩展我的EF类的类,以创建一个连接你正在谈论的两个属性的新属性。然后,如果您还想接受一个值的设置,并将其拆分为存储二,则可以定义所需的任何业务规则。
I would add a partial class to extend my EF class, to create a new property that concatenates the two you're talking about. You could then define any business rule you want if you want to also accept a setting of one value, and split it to store two.


这篇关于实体框架映射问题Concat值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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