就像一个例子我在codeproject上使用本文中的代码:http://www.codeproject.com/Articles/234606/Creating-a-Many-To-Many-Mapping-Using-Code-First

我试图在我的代码中做类似的事情,但我也想要一个数量属性,所以:
我想我必须在名为Quantity的PersonCourses表中添加一列,但我不知道如何在Code First中执行此操作.
代码:
public class Person
{
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public ICollection<Course> CoursesAttending { get; set; }
public Person()
{
CoursesAttending = new HashSet<Course>();
}
}
public class Course
{
public int CourseId { get; set; }
public string Title { get; set; }
public ICollection<Person> Students { get; set; }
public Course()
{ …Run Code Online (Sandbox Code Playgroud) 有人可以帮我翻译成LINQ吗?我有一个字符串数组(step.Variables),一个字典(参数),我希望参数中的所有对,其中键是step.Variables.
这段代码有效,但我想使用LINQ,我无法弄清楚如何翻译:
parameters = new Dictionary<string, string>();
foreach (string variable in step.Variables)
{
if (Parameters.ContainsKey(variable))
{
parameters[variable] = Parameters[variable];
}
}
Run Code Online (Sandbox Code Playgroud)
这是我最好的猜测,但得到了解释:
var parameters = Parameters.ToDictionary(pair => step.Variables.Contains(pair.Key.ToString())).Select(pair => pair);
"System.ArgumentException: 'An item with the same key has already been added.'":
Run Code Online (Sandbox Code Playgroud)