开发者

How to map a List<int> to a ModificationMapping SP for Insert in EF4?

开发者 https://www.devze.com 2023-03-05 02:50 出处:网络
I have an entity with Entity { int Id; object otherProperties; List<int> ForeignIds; } I have written an Insert SP that takes:

I have an entity with

Entity
{
    int Id;
    object otherProperties;
    List<int> ForeignIds;
}

I have written an Insert SP that takes:

@Id INT,
@ForeignId INT

How can I map a List to a SP for Insert for a Modification Mapping that would insert a row with the Id and an element from ForeignIds for each element in ForeignId?

E.g.

Entity(){ id=1; For开发者_如何学CeignIds = new List<int>(){2,3};}

Would insert:

Id | ForeignId

1 | 2

1 | 3


You cannot map this. EF doesn't understand List of scalar types. You must manually iterate the list and execute stored procedure for each item in the collection. You can map the procedure as function import or execute it directly by objectContext.ExecuteStoreCommand.

0

精彩评论

暂无评论...
验证码 换一张
取 消