本文介绍了CTP5 - Code First不在数据库中生成关联集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

采取以下简单类和关联的DbContext

Take the following simple class and associated DbContext

public class Test
{
	public Test()
	{
		Keywords = new Collection<string>();
	}

	public int Id { get; set; }
	public string Name { get; set; }
	public ICollection<string> Keywords { get; set; }
}

public class TestDbContext : DbContext
{
	public TestDbContext()
	{
		Database.Delete();
		Database.CreateIfNotExists();
	}

	public DbSet<Test> Tests { get; set; }

	protected override void OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder)
	{		
		base.OnModelCreating(modelBuilder);
	}
}





The type 'System.Collections.Generic.ICollection<string>' must be a non-nullable value type in order to use it as parameter 'T' 
in the generic type or method 'System.Data.Entity.ModelConfiguration.Configuration.Types.StructuralTypeConfiguration<TStructuralType>
.Property<T>(System.Linq.Expressions.Expression<System.Func<TStructuralType,T>>)'

Any ideas how to create the necessary table relationships between test class and the keywords property?

推荐答案

 


public class Test
{
	public Test()
	{
		Keywords = new Collection<KeyWord>();
	}

	public int Id { get; set; }
	public string Name { get; set; }
	public ICollection<KeyWord> Keywords { get; set; }
}


public class KeyWord
{ <br/>
       public int Id { get; set; }
    public string Word { get; set; }
    // ..
}


这篇关于CTP5 - Code First不在数据库中生成关联集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:35