C# 将数组放入列中
我想先使用EF code在表C# 将数组放入列中,c#,entity-framework,sql-server-2008,ef-code-first,C#,Entity Framework,Sql Server 2008,Ef Code First,我想先使用EF code在表任务中创建一列,这是一个数组。怎么做 public class Task { // my presumption code public string[] Attempts { get; set; } 尝试失败 AttemptsMetadata---maybe string Time ---DataTime Answered ---bool 创建要在代码中使用的属性(并标记为ignore)和
任务
中创建一列,这是一个数组。怎么做
public class Task
{
// my presumption code
public string[] Attempts { get; set; }
尝试
失败
AttemptsMetadata---maybe string
Time ---DataTime
Answered ---bool
创建要在代码中使用的属性(并标记为ignore)和要在代码中使用的其他属性 已编辑
public class Task
{
[Ignore]
public string[] Attempts { get; set; }
public string AttemptsMetadata
{
get
{
return Attempts != null && Attempts.Any()
? Attempts.Aggregate((ac, i) => ";" + ac + i).Substring(1)
: null;
}
set { Attempts = value.Split(';'); }
}
}
PS:这种策略有一个缺陷。使用存储库表达式时,不能使用ignore属性。但是我从来没有找到另一种方法来做到这一点。其他方法如时间如何?它不是一根弦。我的意思是我应该将尝试定义为对象而不是字符串数组吗?如果您有一个基本类型的数组,您可以使用这种方法,但是如果您使用非基本类型,我建议您创建一个表来存储此信息,并使用外键来创建关系。在LINQ中,这种关系将像ICollection属性一样表示(它不是数组,但非常接近于数组)。