假设我有一个通用接口 IService<T>和一个实现它的类Service : IService<Bar>
我创建了该接口的代理:
var proxy = new DynamicProxy<IService<Bar>>(new Service()).GetTransparentProxy() as IService<Bar>;
Run Code Online (Sandbox Code Playgroud)
DynamicProxy是RealProxy的一个简单实现:
public class DynamicProxy<I> : RealProxy
{
private I _decorated;
public DynamicProxy(I decorated) : base(typeof(I))
{
this._decorated = decorated;
}
public override IMessage Invoke(IMessage msg)
{
IMethodCallMessage methodCall = (IMethodCallMessage)msg;
MethodInfo methodInfo = methodCall.MethodBase as MethodInfo;
return new ReturnMessage(
methodInfo.Invoke(this._decorated, methodCall.InArgs),
null,
0,
methodCall.LogicalCallContext,
methodCall);
}
}
Run Code Online (Sandbox Code Playgroud)
直接使用我的代理时它工作正常:
IEnumerable<Bar> bars = new List<Bar>() { new Bar { id = 2 }, new Bar { id …Run Code Online (Sandbox Code Playgroud) 我有Pocos和可以为空的外键的问题.我有2个表(订单和产品),每个表都有一个复合主键(orderid,orderid2)和(productid,productid2)我在两个表之间设置了一个0,1 ..*关联.一个订单可以与0或1个产品相关.一个产品有*与他有关的订单.
如何崩溃:
当我向产品的订单列表添加订单时,它会崩溃尝试修复关联(在新订单上设置产品导航属性)
CREATE TABLE [dbo].[Products](
[productid] [int] IDENTITY(1,1) NOT NULL,
[productid2] [int] NOT NULL,
[productname] [nchar](10) NULL,
CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED
(
[productid] ASC,
[productid2] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[Orders](
[orderid] [int] NOT NULL,
[orderid2] [int] NOT NULL,
[ordername] [nchar](10) NULL,
[productid] [int] NULL,
[productid2] [int] NULL,
CONSTRAINT [PK_orders] PRIMARY KEY CLUSTERED
( …Run Code Online (Sandbox Code Playgroud)