OData made from objects - vb.net

Lets say I have a class called "Item" and "SubItems"
Public Class SubItem
Private _SubItemName As String
Public Property SubItemName() As String
Get
Return _SubItemName
End Get
Set(ByVal value As String)
_SubItemName = value
End Set
End Property
End Class
<DataServiceKey("Name")> _
Public Class Item
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Private _SubItems As List(Of SubItem)
Public Property SubItems() As List(Of SubItem)
Get
Return _SubItems
End Get
Set(ByVal value As List(Of SubItem))
_SubItems = value
End Set
End Property
End Class
How would I create a service that would return a list of Items and upon looking up an individual item I would be able to see the sub items.

You can check out WCF Data Servies reflection provider, e.g.,
http://blogs.msdn.com/b/alexj/archive/2010/06/11/tip-56-writing-an-odata-service-using-the-reflection-provider.aspx
http://msdn.microsoft.com/en-us/library/dd728281.aspx
Hope this helps.

Related

How to use the following model class (Framework 4.7) in a Framework 2.0?

I have the following model class used in my .NET Framework 4.7.2 project which get and set data from an API.
I have to use the same model class in a .NET 2.0 Project which will have to get and set the same object get from a HTTP request (not API)
But if i try just to copy paste it i get the error which says that i need a setter on it.
Here is how my model looks like:
Public Class PDT
Public Class Documento
Public Property testata As Testata
Public Property corpo() As IEnumerable(Of Corpo)
End Class
Public Class Testata
Public Property id As Integer
Public Property cod As String
Public Property tipo As String
Public Property cod_fornitore As String
Public Property desc_fornitore As String
Public Property data As String
Public Property num_pv As String
Public Property desc_pv As String
Public Property num_pv_destinazione As String
Public Property desc_pv_destinazione As String
Public Property num_ordine As String
Public Property inviato As Boolean
End Class
Public Class Corpo
Public Property barcode As String
Public Property desc As String
Public Property um As String
Public Property qta As Single
Public Property id_testata As Integer
Public Property tipo_frontalino As String
Public Property timestamp As Long
End Class
End Class
PS I've tried setting getter and setters like this for each property:
Public Property testata() As Testata
Get
End Get
Set(ByVal value As Testata)
End Set
End Property
But by passing data in that object returns always Nothing.
UPDATE my class with getters and setters:
Public Class PDT
Public Class Documento
Private _testata As Testata = Nothing
Public Property testata As Testata
Get
Return _testata
End Get
Set(ByVal value As Testata)
_testata = value
End Set
End Property
Private _corpo As IEnumerable(Of Corpo) = Nothing
Public Property corpo As IEnumerable(Of Corpo)
Get
Return _corpo
End Get
Set(ByVal value As IEnumerable(Of Corpo))
_corpo = value
End Set
End Property
End Class
Public Class Testata
Private _id As Integer = Nothing
Public Property id As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
_id = value
End Set
End Property
Private _cod As String = Nothing
Public Property cod As String
Get
Return _cod
End Get
Set(ByVal value As String)
_cod = value
End Set
End Property
Private _tipo As String = Nothing
Public Property tipo As String
Get
Return _tipo
End Get
Set(ByVal value As String)
_tipo = value
End Set
End Property
Private _cod_fornitore As String = Nothing
Public Property cod_fornitore As String
Get
Return _cod_fornitore
End Get
Set(ByVal value As String)
_cod_fornitore = value
End Set
End Property
Private _desc_fornitore As String = Nothing
Public Property desc_fornitore As String
Get
Return _desc_fornitore
End Get
Set(ByVal value As String)
_desc_fornitore = value
End Set
End Property
Private _data As String = Nothing
Public Property data As String
Get
Return _data
End Get
Set(ByVal value As String)
_data = value
End Set
End Property
Private _num_pv As String = Nothing
Public Property num_pv As String
Get
Return _num_pv
End Get
Set(ByVal value As String)
_num_pv = value
End Set
End Property
Private _desc_pv As String = Nothing
Public Property desc_pv As String
Get
Return _desc_pv
End Get
Set(ByVal value As String)
_desc_pv = value
End Set
End Property
Private _num_pv_destinazione As String = Nothing
Public Property num_pv_destinazione As String
Get
Return _num_pv_destinazione
End Get
Set(ByVal value As String)
_num_pv_destinazione = value
End Set
End Property
Private _desc_pv_destinazione As String = Nothing
Public Property desc_pv_destinazione As String
Get
Return _desc_pv_destinazione
End Get
Set(ByVal value As String)
_desc_pv_destinazione = value
End Set
End Property
Private _num_ordine As String = Nothing
Public Property num_ordine As String
Get
Return _num_ordine
End Get
Set(ByVal value As String)
_num_ordine = value
End Set
End Property
Private _inviato As Boolean = Nothing
Public Property inviato As Boolean
Get
Return _inviato
End Get
Set(ByVal value As Boolean)
_inviato = value
End Set
End Property
End Class
Public Class Corpo
Private _barcode As String = Nothing
Public Property barcode As String
Get
Return _barcode
End Get
Set(ByVal value As String)
_barcode = value
End Set
End Property
Private _desc As String = Nothing
Public Property desc As String
Get
Return _desc
End Get
Set(ByVal value As String)
_desc = value
End Set
End Property
Private _um As String = Nothing
Public Property um As String
Get
Return _um
End Get
Set(ByVal value As String)
_um = value
End Set
End Property
Private _qta As Single = Nothing
Public Property qta As Single
Get
Return _qta
End Get
Set(ByVal value As Single)
_qta = value
End Set
End Property
Private _id_testata As Integer = Nothing
Public Property id_testata As Integer
Get
Return _id_testata
End Get
Set(ByVal value As Integer)
_id_testata = value
End Set
End Property
Private _tipo_frontalino As String = Nothing
Public Property tipo_frontalino As String
Get
Return _tipo_frontalino
End Get
Set(ByVal value As String)
_tipo_frontalino = value
End Set
End Property
Private _timestamp As Long = Nothing
Public Property timestamp As Long
Get
Return _timestamp
End Get
Set(ByVal value As Long)
_timestamp = value
End Set
End Property
End Class
End Class
I'm pretty sure VB.NET didn't have auto-properties back then, so you will need to change your code to use the classic properties with a backing field. For example:
' Backing field
Private _cod As String = "Empty"
' Classic property getter and setter
Property cod As String
Get
Return _cod
End Get
Set(ByVal value As String)
_cod = value
End Set
End Property

Combine two tables into one entity framework? (SQLite)

I am using the EntityFramework.SQLite library and for the life of me can not figure out how to combine two tables together into a temporary table for display purposes in xaml code.
Here's the code for my two tables I want to combine which is about all I am using right now besides a class for my temp table called CategoryList (this is part of the business/data logic dll library):
Partial Public Class CategoryList
Public Sub New()
Me.CategoryInfo = New CategoryReference
'Me.CategoryCode = New HashSet(Of CategoryCodes)
Me.CategoryCodes = New CategoryCodes
End Sub
Public Property MyId As Integer
<Key, ForeignKey("CodeID")>
<Required>
Public Property CodeID As Integer
<Key, ForeignKey("CategoryID")>
Public CategoryID As Integer
'Public Property CategoryCode As ICollection(Of CategoryCodes)
Public Property CategoryInfo As CategoryReference
' Public Property CategoryInfo As ICollection(Of CategoryReference)
Public Property CategoryCodes As CategoryCodes
End Class
<Table("CategoryCodes")>
Public Class CategoryCodes 'category shortnames/codes
<MaxLength(100)>
<Required>
Public Property CategoryCode As String
Get
Return _CategoryCode
End Get
Set(value As String)
_CategoryCode = value
End Set
End Property
Private _CategoryCode As String
'<NotNull>
' <PrimaryKey>
'<Unique(Name:="UQ__CategoryCodes__0000000000000081_CategoryCodes", Order:=0)>
<Key>
<Required>
Public Property CodeID As Integer
Get
Return CategoryCode
End Get
Set(value As Integer)
_CodeID = value
End Set
End Property
Private _CodeID As Integer
End Class
<Table("CategoryReference")>
Partial Public Class CategoryReference 'table design for category data
<MaxLength(100)>
Public Property CategoryName As String
Get
Return _CategoryName
End Get
Set(value As String)
_CategoryName = value
End Set
End Property
Private _CategoryName As String
<MaxLength(100)>
Public Property CategoryDescription As String
Get
Return _CategoryDescription
End Get
Set(value As String)
_CategoryDescription = value
End Set
End Property
Private _CategoryDescription As String
'<Unique(Name:="UQ__CatagoryReference__000000000000005F_CatagoryReference", Order:=0)>
<ForeignKey("CodeID")>
<Required>
Public Property CodeID As Integer
Get
Return _CodeID
End Get
Set(value As Integer)
_CodeID = value
End Set
End Property
Private _CodeID As Integer
'<Unique(Name:="UQ__CatagoryReference__000000000000005A_CatagoryReference", Order:=0)>
<Key>
<Required>
Public Property CategoryID As Integer
Get
Return _CategoryID
End Get
Set(value As Integer)
_CategoryID = value
End Set
End Property
Private _CategoryID As Integer
End Class
It may seem long but the tables are very simple and the get/set blocks make it look long (A vb.net editor can turn them into simple property's if she/he wishes). I may be using the CategoryList class wrong but here's where I use it in my xaml datasource in my main application code (I have business logic/data processing in a dll library):
Private Property ViewModel As List(Of UIELLUWP.DataAccess.CategoryList)
Dim categories As New UIELLUWP.DataAccess.SQLiteDb
ViewModel = categories.Categories.ToList
Errors received with current code:
I receive an error that Table "CategoryList" does not exist when I run the above code.
my solution I found out to this question was to add asnotracking because tracking was taking place.

In vb.net, defining a dictionary type in a class

New to using a Dictionary list.
I have an api that is returning a "task object" defined as:
id As Integer
options As Dictionary(string, string)
So I am defining a class called Task to store the returned "task object".
Public Class Task
Private _id As Integer
Public Property Id() As Integer
Get
Return _id
End Get
Set(value As Integer
_id = value
End Set
End Property
Private _optionlist As New List(Of Option)
Public Property OptionList() As List(Of Option)
Get
Return _optionlist
End Get
Set(ByVal value As List(Of Option))
_optionlist = value
End Set
End Property
End Class
Public Class Option
Private _key As String
Public Property Key() As String
Get
Return _key
End Get
Set(value As String)
_key = value
End Set
End Property
Private _value As String
Public Property Value() As String
Get
Return _value
End Get
Set(value As String)
_value = value
End Set
End Property
End Class
I will assign the "task object" returned from the api to this Task class.
I defined options as a list. Is that correct?
I will also have to read the option in my class and later repopulate it to send back to the api via function call.
Could use some help...thanks.
You can add the property to the class directly:
Public Class Task
Private _id As Integer
Private options As Dictionary(of string, string)
You can also create Get and Set methods for the "options" parameter.

How to do a collection property inside another collection in user control

I have a user control with a property "Rules" that is a generic list.
Every "rule" is associated to a combobox control and i have to create a property to host data for the combobox. I used another generic list to accomplish this.
In design works well, i can add items normally in property grid, but when i run the program the values are not maintained.
Rules property:
Private _regras As New List(Of ParametrosColunasGrid)
<Category("Ecletica")> _
<Browsable(True)> _
<System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)>
Public Property Regras() As List(Of ParametrosColunasGrid)
Get
Return _regras
End Get
Set(value As List(Of ParametrosColunasGrid))
_regras = value
End Set
End Property
Public Class ParametrosColunasGrid
'...
Private _itens_Combo As New List(Of ItemComboBox)
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public Property ItensCombo As List(Of ItemComboBox)
Get
Return _itens_Combo
End Get
Set(value As List(Of ItemComboBox))
_itens_Combo = value
End Set
End Property
'...
End Class
ItemComboBox Class:
<Serializable()>
Public Class ItemComboBox
Public Property Value As String
Public Property Key As String
Public Overrides Function ToString() As String
Return _Value
End Function
End Class

how to deserealizate manually

i have this strings
{\"Data\":null,\"ErrorCode\":0,\"IsSuccess\":false,\"Message\":\"No hay informacion para descargar\",\"SuccessCode\":100}
{\"Data\":{\"BranchCodes\":[\"30\"],\"ProcessId\":86},\"ErrorCode\":0,\"IsSuccess\":true,\"Message\":null,\"SuccessCode\":0}
{\"Data\":{\"BranchCodes\":[\"30\",\"97\"],\"ProcessId\":87},\"ErrorCode\":0,\"IsSuccess\":true,\"Message\":null,\"SuccessCode\":0}
i want to convert to this object
Class WorkGroupMetric
Public Property Data() As Data
Get
Return m_Data
End Get
Set(ByVal value As Data)
m_Data = Value
End Set
End Property
Private m_Data As Data
Public Property ErrorCode() As Integer
Get
Return m_ErrorCode
End Get
Set(ByVal value As Integer)
m_ErrorCode = Value
End Set
End Property
Private m_ErrorCode As Integer
Public Property IsSuccess() As Boolean
Get
Return m_IsSuccess
End Get
Set(ByVal value As Boolean)
m_IsSuccess = Value
End Set
End Property
Private m_IsSuccess As Boolean
Public Property Message() As String
Get
Return m_Message
End Get
Set(ByVal value As String)
m_Message = Value
End Set
End Property
Private m_Message As String
Public Property SuccessCode() As Integer
Get
Return m_SuccessCode
End Get
Set(ByVal value As Integer)
m_SuccessCode = Value
End Set
End Property
Private m_SuccessCode As Integer
End Class
Public Class Data
Public Property BranchCodes() As List(Of String)
Get
Return m_BranchCodes
End Get
Set(ByVal value As List(Of String))
m_BranchCodes = value
End Set
End Property
Private m_BranchCodes As List(Of String)
Public Property ProcessId() As Integer
Get
Return m_ProcessId
End Get
Set(ByVal value As Integer)
m_ProcessId = Value
End Set
End Property
Private m_ProcessId As Integer
End Class
i need help i am doing this in visual studio 2005, with scriptask for ssis.
i cant uses JavaScriptSerializer or similar, this must to be manually.
You really want to avoid doing this manually, I would investigate json.net, which is not part of the .net framework and should work with vs2005. http://james.newtonking.com/json