English 中文(简体)
如何处理一种观点模式的多种事例
原标题:How to handle multiple instances of a model on one view

我有一个称为“装置”的模范类,即:

public class DeviceType
{
    int ID { get; set; }
    String Type { get; set; }
    String Description { get; set; } 
    EntityCollection<AttributeDefinition> AttributeDefinitions { get; set; }
}

定义如下:

public class AttributeDefinition
{
    int ID { get; set; }
    String Name { get; set; }
    bool IsPrivate { get; set; }
    bool IsInherited { get; set; }
}

我试图为一种装置铺设细节。 在这种观点中,我要向每个阿特曼底省提交一份表格,作为一条可调用的行文,以便你能够在同一页上更新每个阿特曼底。

我试图遵循,但这一员额。 我发现这一错误:

The EntityCollection has already been initialized. The InitializeRelatedCollection method should only be called to initialize a new EntityCollection during deserialization of an object graph.

如果没有像自治政府这样的东西,是否有办法这样做? 或许要使用表格,或者使用一种观点吗?

最佳回答

通常不使用名称空间的类别System.Data。 采用<代码>List或另一种收集类别修改其观点模式。 当你阅读数据库的数据并检索<代码>意向书<>代码>时,你需要将贵实体转换为POCO ojbect,并利用这一新结构作为参考模式。

问题回答

I would suggest that you create a single entity/model just for your view. I m not sure how the DeviceType and AttributeDefinition are related but your model might look something like this:

public class DeviceTypeEditModel
{
    int ID { get; set; }
    String Type { get; set; }
    String Description { get; set; } 
    EntityCollection<AttributeDefinition> AttributeDefinitions { get; set; }
    AttributeDefinition AttributeDefinition { get; set;}
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签