简短地说,我有多对多的关系
Cases -----< CaseSubjectRelationships >------ CaseSubjects
更全面:案例(ID,CaseTypeID,.......)
CaseSubjects(ID,DisplayName,CRMSPIN)
CaseSubjectsRelationships(CaseID,SubjectID,PrimarySubject,RelationToCase,...)
在我的多对多链接表中是与主题与特定案例的关联相关的其他属性 - 例如,开始日期,结束日期,与案例的自由文本关系(观察者,创建者等)
已创建实体框架数据模型 - ASP.NET 4.0版
我有一个带有一个方法的WCF服务,该方法CreateNewCase接受一个Case对象(由实体框架创建的实体)作为其参数- 它的工作是将案例保存到数据库中.
WCF服务由第三方工具调用.这是发送的SOAP:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<CreateNewCase xmlns="http://tempuri.org/">
<c xmlns:a="http://schemas.datacontract.org/2004/07/CAMSModel">
<a:CaseSubjectsRelationships>
<a:CaseSubjectsRelationship>
<a:CaseSubject>
<a:CRMSPIN>601</a:CRMSPIN>
<a:DisplayName>Fred Flintstone</a:DisplayName>
</a:CaseSubject>
<a:PrimarySubject>true</a:PrimarySubject>
<a:RelationToCase>Interested</a:RelationToCase>
<a:StartDate>2011-07-12T00:00:00</a:StartDate>
</a:CaseSubjectsRelationship>
<a:CaseSubjectsRelationship>
<a:CaseSubject>
<a:CRMSPIN>602</a:CRMSPIN>
<a:DisplayName>Barney Rubble</a:DisplayName>
</a:CaseSubject>
<a:RelationToCase>Observer</a:RelationToCase>
<a:StartDate>2011-07-12T00:00:00</a:StartDate>
</a:CaseSubjectsRelationship>
</a:CaseSubjectsRelationships>
<a:CaseType>
<a:Identifier>Change of Occupier</a:Identifier>
</a:CaseType>
<a:Description>Case description</a:Description>
<a:Priority>5</a:Priority>
<a:QueueIdentifier>Queue One</a:QueueIdentifier>
<a:Title>Case title</a:Title>
</c>
</CreateNewCase>
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)
WCF引擎正确地将其反序列化为Case实体,当我查看调试器时,所有内容都已正确设置.
我想要做的是,CaseSubject如果数据库中没有CRMSPIN …
我有一个简单的实体,由Entity Framework 4使用VS 2010 RC生成.它看起来像下面的POCO.
public class Company
{
public int ID { get; set; }
public string Name { get; set; }
public string ISOCode { get; set; }
public boolean Active { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的存储库代码如下.'db'是我在构造函数中初始化的上下文.
public void EditCountry(Country countryToEdit)
{
db.Countries.Attach(new Country { ID = countryToEdit.ID });
db.Countries.ApplyCurrentValues(countryToEdit);
db.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
在countryToEdit中将Active字段从false更改为true会生成以下SQL
update [dbo].[Countries]
set [Name] = @0, [ISOCode] = @1, [Active] = @2
where ([ID] = @3)
@0 nvarchar(256),@1 nvarchar(12),@2 bit,@3 int,@0='Algeria',@1='DZ',@2=1,@3=4
Run Code Online (Sandbox Code Playgroud)
这是预料之中的.
如果我在countryToEdit中将Active字段从true更改为false,则会生成以下SQL
update [dbo].[Countries] …Run Code Online (Sandbox Code Playgroud)