• Webseitenerstellung und -hosting
  • .NET Anwendungsentwicklung
  • softwaregesteuerte Prozessoptimierung
  • .NET

    Programmierung

  • WebseitenErstellung

    undHosting

  • softwaregesteuerte

    Prozessoptimierung

  • Konzeption

    und Beratung

%AM, %05. %504 %2013 %11:%Jul

Entitäten klonen und vergleichen mit dem Entity Framework 4

geschrieben von
Artikel bewerten
(0 Stimmen)
Da solche Funktionen erst mit EF5 bzw. .NET 4.5 halbwegs vernünftig zur Verfügung stehen ("AsNoTracking") hier eine Möglichkeit um Entitäten zu klonen (als Extension :-))

;
Public Function Clone(Of t As EntityObject)(entity As t, ctx As oraEntities, Optional copyKeys As Boolean = True) As t
Try
Dim cloneE As t = ctx.CreateObject(Of t)()
Dim pis As PropertyInfo() = entity.GetType.GetProperties()

For Each pi As PropertyInfo In pis
Dim attrs As EdmScalarPropertyAttribute() = DirectCast(pi.GetCustomAttributes(GetType(EdmScalarPropertyAttribute), False), EdmScalarPropertyAttribute())

For Each attr As EdmScalarPropertyAttribute In attrs
If Not copyKeys AndAlso attr.EntityKeyProperty Then
Continue For
End If
'Strung und NULL abfangen, wird trotz Standardwert im SQL Server nicht imgesetzt
Dim objVal As Object
If pi.PropertyType = GetType(String) And pi.GetValue(entity, Nothing) Is Nothing Then
objVal = ""
Else
objVal = pi.GetValue(entity, Nothing)
End If
pi.SetValue(cloneE, objVal, Nothing)
Next
Next
Return cloneE
Catch ex As Exception
Throw ex
End Try
End Function


und zu vergleichen


;
Public Function Compare(Of t As EntityObject)(entityOriginal As t, entityCopy As t) As Boolean
Try
'Um Änderungen einer Entität festzustellen (t.equals funktioniert aufgrund der Abhängigkeiten mit anderen Tabellen nicht)
Dim pisOrig As PropertyInfo() = entityOriginal.GetType.GetProperties()

For Each piOrig As PropertyInfo In pisOrig
Dim attrs As EdmScalarPropertyAttribute() = DirectCast(piOrig.GetCustomAttributes(GetType(EdmScalarPropertyAttribute), False), EdmScalarPropertyAttribute())
If attrs.Count > 0 Then 'Fremdschlüsseltabellen ausschliessen
Dim objOrig As Object = If(GetType(t).GetProperty(piOrig.Name).GetValue(entityOriginal, Nothing) Is Nothing, "", GetType(t).GetProperty(piOrig.Name).GetValue(entityOriginal, Nothing))
Dim objCopy As Object = If(GetType(t).GetProperty(piOrig.Name).GetValue(entityCopy, Nothing) Is Nothing, "", GetType(t).GetProperty(piOrig.Name).GetValue(entityCopy, Nothing))
If Not objOrig.Equals(objCopy) Then
Return False
End If
End If
Next

Return True
Catch ex As Exception
Throw ex
End Try
End Function


Verknüfte Tabellen werden dabei allerdings nicht übernommen!		
Gelesen 41378 mal Letzte Änderung am %PM, %24. %643 %2015 %14:%Jun

254 Kommentare

  • Kommentar-Link DichaelANYMN %PM, %16. %889 %2024 %20:%Jun gepostet von DichaelANYMN

    Today, I went to the beachfront with my kids. I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is totally off topic but I had to tell someone!
    купить диплом в севастополе
    http://medhelp-dent.ru
    http://diploms-help.ru
    http://studenta-blog.ru

    купить диплом магистра

  • Kommentar-Link Timsothymat %PM, %16. %885 %2024 %20:%Jun gepostet von Timsothymat

    Hi there to every one, the contents present at this web page are genuinely amazing for people experience, well, keep up the nice work fellows.
    http://photoconnor.space/PHPFusion/profile.php?lookup=12076

    купить диплом в бугульме
    http://npshi12.ru

    купить диплом в мурманске

  • Kommentar-Link Lewisbib %PM, %16. %820 %2024 %18:%Jun gepostet von Lewisbib

    Hi to every single one, it's genuinely a nice for me to pay a quick visit this site, it includes useful Information.
    http://janews.com.au/modules/newbb/viewtopic.php?topic_id=6903&forum=14&post_id=6903

    купить диплом в елабуге
    http://med-spravka911.ru

    купить диплом в нижнекамске

  • Kommentar-Link Shanehurdy %PM, %16. %784 %2024 %17:%Jun gepostet von Shanehurdy

    WOW just what I was looking for. Came here by searching for %meta_keyword%
    http://helplearn.ru/task.php?id=14973

    купить диплом в бузулуке
    http://irkutsk-arbitr.ru

    купить диплом в артеме

  • Kommentar-Link Lhanehurdy %PM, %16. %720 %2024 %16:%Jun gepostet von Lhanehurdy

    Everything said was actually very logical. But, think on this, what if you added a little information? I mean, I don't want to tell you how to run your blog, but suppose you added a title that grabbed folk's attention? I mean %BLOG_TITLE% is kinda vanilla. You might glance at Yahoo's home page and see how they create post headlines to get viewers to click. You might add a video or a pic or two to grab readers excited about what you've written. In my opinion, it could make your posts a little livelier.
    http://testkids.ru/zdorove/sindrom-dyryavoj-kishki.html

    купить диплом в когалыме
    http://i126.ru

    купить диплом в набережных челнах

  • Kommentar-Link Lewisbib %PM, %16. %655 %2024 %14:%Jun gepostet von Lewisbib

    Hi, I want to subscribe for this website to take most up-to-date updates, so where can i do it please help.
    купить диплом лаборанта
    http://git-ugra.ru
    http://transcollege.ru
    http://47gbdou-pushkin.ru

    купить диплом химика

  • Kommentar-Link Gichardjah %PM, %16. %605 %2024 %13:%Jun gepostet von Gichardjah

    Hello to every body, it's my first go to see of this webpage; this weblog contains amazing and truly excellent data for readers.
    купить диплом в россоши
    http://o2omarketing.pro
    http://to66minust.ru
    http://nti-nastavnik.ru

    купить диплом в березниках

  • Kommentar-Link Gichardjah %PM, %16. %579 %2024 %12:%Jun gepostet von Gichardjah

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
    купить диплом в усолье-сибирском
    http://kam96.ru
    http://svetilnikild.ru
    http://vm-tver.ru

    можно ли купить диплом

  • Kommentar-Link FobertUnife %AM, %16. %534 %2024 %11:%Jun gepostet von FobertUnife

    Thank you for some other magnificent article. Where else could anyone get that type of info in such a perfect way of writing? I have a presentation next week, and I am at the search for such info.
    купить диплом программиста
    http://svetilnikild.ru
    http://diplomy-plus.com
    http://uk-ahml.ru

    купить диплом в петрозаводске

  • Kommentar-Link Timsothymat %AM, %16. %306 %2024 %06:%Jun gepostet von Timsothymat

    Hi are using Wordpress for your blog platform? I'm new to the blog world but I'm trying to get started and set up my own. Do you need any html coding expertise to make your own blog? Any help would be really appreciated!
    купить диплом в троицке
    http://npshi12.ru
    http://gmzotvet.ru
    http://1matematiki.ru

    купить диплом в октябрьском

Schreibe einen Kommentar

Bitte achten Sie darauf, alle Felder mit Stern * zu füllen. HTML-Code ist nicht erlaubt.