只要我在班级和班级ClassSameAssembly相同的班级中,下面的代码就能正常运行Program.但是当我将类移动ClassSameAssembly到一个单独的程序集时,RuntimeBinderException会抛出一个(见下文).有可能解决它吗?
using System;
namespace ConsoleApplication2
{
public static class ClassSameAssembly
{
public static dynamic GetValues()
{
return new
{
Name = "Michael", Age = 20
};
}
}
internal class Program
{
private static void Main(string[] args)
{
var d = ClassSameAssembly.GetValues();
Console.WriteLine("{0} is {1} years old", d.Name, d.Age);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:'object'不包含'Name'的定义
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at ConsoleApplication2.Program.Main(String[] args) in C:\temp\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line …Run Code Online (Sandbox Code Playgroud) 我在以下场景中遇到了db生成问题:
1.cs First.Entities命名空间中的项目实体maped到First_Project表.
namespace First.Entities
{
#region using section
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using System.Diagnostics.CodeAnalysis;
#endregion
[Table("First_Project")]
public class Project
{
[Key]
public int Id
{
get;
set;
}
[Required]
[MaxLength(1000)]
public string Name
{
get;
set;
}
}
}
Run Code Online (Sandbox Code Playgroud)
2.cs在Second.Entities命名空间中的项目实体maped到Second_Project表.
namespace Second.Entities
{
#region using section
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using System.Diagnostics.CodeAnalysis;
#endregion
[Table("Second_Project")]
public class Project
{
[Key]
public int Id
{
get;
set;
}
[Required]
[MaxLength(1000)]
public string Name
{
get;
set;
} …Run Code Online (Sandbox Code Playgroud) 以下示例是否可以与实体框架并行工作?
using (var dbContext = new DB())
{
var res = (from c in dbContext.Customers
orderby c.Name
select new
{
c.Id,
c.Name,
c.Role
}
).ToDictionary(c => c.Id,
c => new Dictionary<string, object> {
{ "Name",c.Name },
{ "Role", c.Role }
});
}
Run Code Online (Sandbox Code Playgroud)
例如,如果我添加AsParrallel,将会改变什么?
using (var dbContext = new DB())
{
var res = (from c in dbContext.Customers
orderby c.Name
select new
{
c.Id,
c.Name,
c.Role
}
).AsParallel().ToDictionary(c => c.Id,
c => new Dictionary<string, object> {
{ "Name",c.Name },
{ "Role", …Run Code Online (Sandbox Code Playgroud)