开发者

LINQ to Entities Converting Stored Procedure to L2E Query

I have the following stored procedure that I am trying to convert to a LINQ to Entities query:

SELECT
    SR.*,
    F.*
FROM
    Users AS U,
    UsersToClients AS UM,
    Filings AS F,
    Records AS SR
    LEFT OUTER JOIN RecordsMappings AS MAP ON
        MAP.[MappingID] = SR.[MappingID]
WHERE
    UM.[ClientID] = @clientID AND
    U.[Username] LIKE UM.[Username] AND
    U.[Deleted] = 0 AND
    F.[Username] LIKE U.[Username] AND
    SR.[FilingID] = F.[FilingID] AND
    SR.[RecordType] = @recordType AND
    SR.[ClientID] = @clientID AND
    dbo.uf_Record_IsValuable(SR.[RecordID], 0) = 1

I have the following query which is almost exactly what's happening in the stored proc:

var records =
    from sr in context.SecuritiesRecords
    from u in context.Users
    from um in context.UsersToClients
    from f in context.Filings
    where
        um.ClientID == clientID &&
        String.Compare(u.Username, um.Username, true) == 0 &&
        !u.Deleted &&
        String.Compare(u.Username, f.Username, true) == 0 &&
        sr.FilingID == f.FilingID &&
        sr.RecordType == recordType &&
        sr.ClientID == um.ClientID
    se开发者_运维百科lect sr;

The problem arises with the last WHERE clause from the stored proc which is a call to a user defined function that filters out records based on a bunch of conditional logic. I didn't want to call the stored proc from L2E because I will be adding more where clauses to filter the data down and the stored proc could pull in lots of records which I would then be whittling down in memory on the LINQ end.

What are my options here?

EDIT:

I have successfully created a Model Defined Function with the following:

<DefiningExpression>
    1
</DefiningExpression>

But when I try to insert my UDF into the defining expression (I have also added it to the model) as follows:

<DefiningExpression>
    uf_Record_IsValuable(100, 0)
</DefiningExpression>

I get the following error: 'uf_Record_IsValuable' cannot be resolved into a valid type or function.


EF4: Model-Defined Functions Level 1 & 2

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜