none
entity Framework : A calculated property that accept an external argument RRS feed

  • Question

  • Hello !

    I'm using entity framework.This is my model :

    Partial Public Class Myobj1
        Public Property id As Integer
        Public Property name As String
        Public Overridable Property Child1 As ICollection(Of Child1) = New HashSet(Of Child1)
    End Class
    Partial Public Class MyObj1
    <NotMapped> Public ReadOnly Property sumvalue As Decimal
        Get
            Return Child1.AsQueryable.Where(function(t1) t1.tp>2).Select(Function(t3) t3.quantity).DefaultIfEmpty.Sum()
    End Get End Property
    Partial Public Class Child1
        Public Property id As Integer
        Public Property tp As integer
        Public Property quantity As Decimal
        Public Property cmh As Decimal
        Public Property MyObj1_ID As Integer
        Public Overridable Property MyObj11 As Myobj1
    End Class

    now on my form I have a query like this :

    dim lst=(Form t in context.Myobj1 select t).Tolist

    And after that query is executed , all the .sumvalue property are filled with the sum values.So this works.

    The problem is that I want to have a custom condition inside the Where clause on partial class .

    This is the situation :

    I'm using predicatebuilder to construct a condition :

    Dim predchild = PredicateBuilder.True(Of child1)()

    I construct the condition step by step in my form before calling the above select query.

    I want that the calculated property to get this predicate as variable.

    So I want something like this , but I don't know how to make it work :

    Partial Public Class MyObj1 <NotMapped> Public ReadOnly Property sumvalue As Decimal Get Return Child1.AsQueryable.Where(??Predchild??).Select(Function(t3) t3.quantity).DefaultIfEmpty.Sum()

    end get End Property

    how can I do this ? Or another way to make this work ?

    Thank you !




    • Edited by dcode25 Wednesday, February 18, 2015 6:00 PM
    Wednesday, February 18, 2015 5:56 PM

Answers