1

我正在开发一个 asp.net mvc 3 应用程序。有一个数据库,但现在我无法向其中添加数据,但该项目仍然首先使用实体​​框架和数据库,所以我在我的解决方案中创建了实体。我想要的是创建一个实体列表,一旦它可以免费使用,它应该代表从查询到数据库的结果。

这是 EF 创建的实体:

    namespace DataAccess
    {
        using System;
        using System.Collections.Generic;

        public partial class MCS_DocumentFields
        {
            public long Id { get; set; }
            public int RowNo { get; set; }
            public int ColumnNo { get; set; }
            public Nullable<bool> IsRequired { get; set; }
            public string QuestionText { get; set; }
            public string FieldValue { get; set; }

            public virtual MCS_ContentTypes MCS_ContentTypes { get; set; }
            public virtual MCS_Documents MCS_Documents { get; set; }
            public virtual MCS_Fields MCS_Fields { get; set; }
        }
    }

I have Extensions so this is the extension for this entity :

namespace DataAccess
{
    [MetadataType(typeof(MCS_DocumentFieldsMetaData))]
    public partial class MCS_DocumentFields : BaseEntity
    {

    }

    internal sealed class MCS_DocumentFieldsMetaData
    {
        [Required]
        public int RowNo { get; set; }

        [Required]
        public int ColumnNo { get; set; }
    }
}

最后在我的控制器中,我创建了包含以下实例的列表MCS_DocumentFields

 List<MCS_DocumentFields> DocumentData = new List<MCS_DocumentFields>()
            {
                new MCS_DocumentFields {Id = 1, RowNo = 1, ColumnNo = 1, IsRequired = true, QuestionText = "alabala", FieldValue = ""},
                new MCS_DocumentFields {Id = 2, RowNo = 1, ColumnNo = 2, IsRequired = true, QuestionText = "", FieldValue = "yes"},
                new MCS_DocumentFields {Id = 3, RowNo = 2, ColumnNo = 1, IsRequired = true, QuestionText = "alabala", FieldValue = "yes"},
                new MCS_DocumentFields {Id = 4, RowNo = 3, ColumnNo = 1, IsRequired = true, QuestionText = "alabala", FieldValue = "yes"},
                new MCS_DocumentFields {Id = 5, RowNo = 4, ColumnNo = 1, IsRequired = false, QuestionText = "alabala", FieldValue = "no"},
                new MCS_DocumentFields {Id = 6, RowNo = 4, ColumnNo = 2, IsRequired = true, QuestionText = "alabala", FieldValue = "no"},
            }

问题是这个 -public virtual MCS_Fields MCS_Fields { get; set; }代表数据库中的 FK,我需要在我的每条记录FiedlId中添加这个值。DocumentData但是我不能FieldId直接使用,而是可以使用实体MCS_Fields,但我不知道如何从那里开始。显然,只是打字MCS_Fields.Id是行不通的......那么我怎样才能在我的列表中模拟呢?

4

0 回答 0