Cast MyEntity To LinqEntity throw a base controller class
Posted
by Mohammad Kani
on Stack Overflow
See other posts from Stack Overflow
or by Mohammad Kani
Published on 2010-04-17T13:28:42Z
Indexed on
2010/04/17
13:33 UTC
Read the original article
Hit count: 294
hi there i design a multilayer we appliction andusing LINQ a my data provider i need to user my own Entites instead o LINQ etities. so i created Entities Project and create my entities in it.
when i get data from contex and cast them to my entities , everything is ok. but when i want to cast on of my entities to linq entity , an exception thrown.
in my linq entity i add CTYPE operator from and to my entities
Exp :
Public Class BaseController(Of LinqEntity As {BaseEntity, New}, MyEntity As ModuleEntities.BaseEntityInfo)
Implements Interfaces.Base(Of ServiceEntity)
'This methd work fine and cast LinqEntity to MyEntity
Public Function GetAll() As List(Of MyEntity )
Dim q = (From x In Context.GetTable(Of LinqEntity)() _
Select x).Cast(Of MyEntityBase)
End Function
Public Sub Update(ByVal entity As MyEntity)
'here is problem
'cast , direct cast , or anything not work
Dim x as LinqEntity = entity
Me.Context.GetTable(Of LinqEntity).InsertOnSubmit(entity)
Me.Context.SubmiChanges()
End Sub
© Stack Overflow or respective owner