Linq To Entities Filtering An Entity Dynamic/Strongly Typed?
Apr 24, 2009
I am binding a Winforms Grid to an entity. (For reasons I won't go into here it must be bound to the entity, not the result a query) The code is as follows:
I have the following LINQ-to-Entities query:[code]This will give me all the resident assignments for the current year/term. Then I have this LINQ-to-Entities query:[code]This will give me all the rooms. I want to iterate through the assignments and based on what room is assigned update the occupancy in reset_occupancy. I'm not 100% sure how to accomplish this. Here is my pseudo code of what I want to accomplish:[code]
Using advWorksContext As New AdventureWorksEntities ' Call the constructor that takes a command string and ObjectContext. Dim productQuery1 As New ObjectQuery(Of Product)("Product", advWorksContext)
[code]....
An ObjectQuery can be enumberated only once. (Subsequent attempts at enumeration throw an exception.) The enumberation takes place in the for each statement. The problem is that if the query is empty attempting a For Each will throw an exception. But if I check for a count:If productQuery1.Count > 0 Then . . .
That eats up my one chance at enumeration. I could nest the For Each in a try/catch block and throw away the empty query exceptions, but that's ugly.
I have the following code compiles without issue. Of course, I get an invalid cast xception when executing the Dim C As IDoThingsC = GetThing_C(). Am I missing something?Would you ever want to return an object that does not meet the interface requirement for a function return value?
Public Class ClassA Public Sub DoThings_A() Debug.Print("Doing A things...")
I'm starting to learn ASP.NET MVC and since I work in a VB.NET shop I'm converting an example from C#. I'm trying to implement a strongly typed view and the example I'm looking at shows the following:
I'm looking for a the shortest/aseist way in VB.NET (or C# but using VB.NET at the moment) to get the string value of a method's name dynamically given the method call.For instance, I have a class like this:
Public Class Blah Public Sub Foo() End Sub End Class
Now Foo is a strongly-typed cover for a dynamic setting and I have an event handler that will fire when the setting changes and return the string name of the setting that changed.
I'd like to be able to switch/select on this string and have a case based on the Foo() method. To do this I need to able to get the string name of the Foo method from the method call itself (i.e. somehow GetMethodName(blahInstance.Foo())).
I'm wanting to have some datatables that are just used temporarily, mainly for creating and listing friendly versions of data that will be easier for the user to read in drop-down combos etc.
I would like them to be strongly typed to pick-up bugs at design-time. However I'm struggling to know how to achieve this. Do I need to create a custom class and inherit from DataTable and build the columns in the class constructor?I don't need a Dataset, just a DataTable?
Firstly here's the code and i will explain my problem underneath. [code...]
Now as you can see I have a variable that holds a value member of the combo box Products which is the productID of the current product selected. Then it searchers through the products datatable and once its found the correct product or not it stores the answer in slectedproductrow. next I test to see if selected product row has found the product if it has i then see if the product has already been added to the order by seraching the the customer current order datatable if it hasn't it adds the current information to the order by using selected product row.
Now the problem i get is when i add the same product it still adds the information again as currentorderrow comes back as nothing everytime even if the product has been added before but if it was in the table which it should be it should skip that bit and just go to add the current qtys toghther.Also if i go to add a diffrent product it overwrites the the other one. So i can't store the customer order. Its like i can't store more than one row. By the way I have a datagrid and can see the product get over wrriten.
Currently I am working on a project developed using VB.Net in Visual Studio 2010.Previously they were using Sql queries directly into SqlCommand of System.Data.SqlClient, but then after i shifted everything to Strongly Typed DataSet and started using TableAdapters every where..Now i just wanna ask that is this way is good for a project...Or Should i shift back to old ones using Just SqlCommands
I am trying to sqlbulkcopy. I have a dataset defined (.xsd). It seems that I cannot use it with sqlbulkcopy. All the information I can find on sqlbulkcopy shows that it can only take a connection string or a variable that contains the connection string.
I'm trying to create a strongly-typed Dictionary class in VB.NET.I'm tired of typing Dim people as Dictionary(Of String, Person)and want to make a PersonDictionary class so I can say Dim people as PersonDictionary.My reference material says to create a new class that inherits the DictionaryBase class. Then override the Add, Remove, and Item Sub/Properties.It seems like a pretty common pattern, is there an easier way?
I'm trying to pass strongly typed FaultExceptions from a WCF service to a Silverlight client but all I'm getting is the generic "The remote server returned an error: NotFound." response, while using the same code to throw generic FaultExceptions works fine. So, if I doThrow New FaultException() I get it back in the e.Error parameter of the Silverlight callback, while a Throw New FaultException(Of clsServiceFault)(clsServiceFaultInstance) results in the not found error.
clsServiceFault has already been declared as a data contract like so: <DataContract()> _ Public Enum ServiceFaultTypes LoginFailed SessionExpired End Enum [Code] .....
The WCF method in which the fault is thrown has been decorated with the FaultContract attribute and I'm also changing the HTTP response status code to 200. <OperationContract()> _ <FaultContract(GetType(clsServiceFault))> _ Public Function GetCustomersData(...) ... System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.StatusCode = Net.HttpStatusCode.OK Throw New FaultException() 'Works Throw New FaultException(Of clsServiceFault)(new clsServiceFault(..)) 'Does not work ... End Function
How can I "search" through a strongly typed list for a string?
I am attempting .Contains(TheString), however it errors stating Unable to cast object of type 'System.String' to type 'o7thCrawler.Typing.ImportantTyping'
Here is the code:
Public Class LinkTyping Public Property Url As String Public Property Title As String
Currently we generate classes in App_Code by returning all the sprocs from all of our databases and adding the correct parameter types and names to a SqlCommand object and then returning it in one giant class. This means we can do things like MyCmd.cmd.Parameters("MyParam").Value = "whatever" when we want to pass parameters to a SqlCommand for a stored procedure without having to add the parameters with their relative data types every single time we make a call. It also means that we have to look up the exposed parameters for each sproc because they are merely strings.
To put it into perspective, for every parameter you want to deal with in a sproc you'd have to do this:
Really this is undesirable as it'd mean an Intranet/Internet application would explode into gazillions of lines of code to achieve really quite simple tasks.We're looking into refactoring this in such a way where we can do something like MyDatabase.MySproc.MyParam("value") instead by making it strongly typed. Unfortunately this means our App_Code folder will be twice the size it already is because such a large quantity of code would be required.
I've written a short example of what I mean:
Public Class MyProc Dim cmd As SqlCommand Public Sub New()
[code]....
Are there alternatives to having to do this that we are unaware of? I'm sure this is a common problem amongst many businesses developing inter/intranet applications.
I want to bind a column of a strongly typed dataset to a combobox. But the problem is i have to get only the distinct values from the column and also when a user inserts a value into that column the new value should be showned in the combobox at the same time.And also i want to make the first row of the combobox to be unselectable..[code]how to make this column distinct values
I cannot figure out for the life of me why I cannot reference a dataset table using the strongly typed name. I created a "news" table in a dataset to write out and read in a simple xml.
If you look at the code below this does not work: 'Dim TableFail As ADataSet.NewsDataTable = ds.NewsDataTable 'Does not work
I can access the table by using an untyped name however: Dim NewsTable As ADataSet.NewsDataTable = ds.Tables("News") What is the proper way of accessing the datasets 'typed' datatables name.
How do I close a connection of strongly typed dataset? I want to backup my database with a zip technique. But I can't access it when my program is open. I've closed connections of all table adapters but it didn't work.
I am using the ASP.NET MVC VB.NET XML Literals View Engine created by Dmitry Robsman and described on his blog in this post.
[URL]
I would like to create strongly typed view pages using this view engine, but it doesn't seem to contain the requisite VbView(Of TModel) generic type by which I would create such a view class.
The end result should look something like this:
Namespace Views.Client Public Class Details(Of Models.Client) Inherits SiteMaster
[Code]....
Once there is a VbView(Of TModel) class that inherits from Dmitry's VbView class, how to hook that up so that it works with standard MVC controllers that call the view like this.
Function Details(ByVal id As Integer) As ActionResult Dim c = SomeGetClientFunction(id) Return View(c) End Function
What is the simplest/cleanest/easiest/best way to handle Null value of a Strongly Typed DataSet in the following case :A base class has a Nullable value that is set through it's constructorThe derived class's constructor has Strongly Typed DataSet Row as parameter and it Throw exception when accessing a null value.Here a simplified example to demonstrate the problem I'm facing. Any resemblance to your code is purely coincidental.
Public MustInherit Class BaseClass Private _Number as Nullable(of integer) Public Sub New(Number as Nullable(of integer))
I'm learning delegates in VB.NET and am confused about delegate types. In reading about delegates, I learned that delegates are a data type that can refer to a method with a particular kind of signature. So in the same way that a String can refer to characters, a delegate can refer to a method (for instance) that takes an integer as input and returns an integer as output. But in playing around with delegates, I found that this was not the case. The code below compiles and runs--even though I don't obey the 'typing' in my delegate signature. I'm confused. Am I missing something?
Public Delegate Function myDelegate(ByVal i As Integer) As Integer' int in, rtrn int Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim md As myDelegate 'should be of type int in, rtrn int md = New myDelegate(AddressOf squared) 'allows assign to string in, string out
When ASP .NET hits the RenderPartial("Openings") line, an exception is thrown ("Could not load type 'System.Web.Mvc.ViewUserControl(of IEnumerable(of OpenSpace))'.") even though the view exists and the proper model is being passed in. The views are all inside the View folder and in this case, they're even in the same subdirectory.[code]
i'm using a strongly-typed dataset and i created a table adapter with a query and i previewed the data and it works fine but when i run the application it can't fill the table with this query and it throws an exception that it violates a constraint orkeyFailed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
System.Data.ConstraintException was unhandled Message=Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
I am working on a project, and have defined a strongly typed dataset. Normally I create a single instance of a dataset and use through out an application. In this case I have need to clone the dataset, and clear 2 of the table and then fill those 2 tables with fake data for creating a sample report. at the end of the retuine, I dispose of the dataset. So I was think all was good.
The following code has two flaws, I can't figure out if they are bugs or by design. From what I have seen it should be possible to write back to the app.config file using the Configuration.Save and according to[url]... the code should work.
The bugs are shown in the source below and appear when you try to set the property or save the config back out.[code]...
What is the best way to provide strongly typed access to the session object? I am planning on turning on Option Strict, which is causing the compiler to complain about my lazy programming technique of directly accessing the session object:
Dim blah As Integer = Session("Blah")
My initial thought is to create a class that wraps the session and provides strongly typed properties for the information stored in the session. However, I cannot decide if the class should be a singleton, or instantiated on every use, or where the code should reside (i.e. within the web project or within a class library).
I'm leaning towards a singleton in my class library, but I don't know if that is the best solution, or if I am missing any other possibilities.
Proposed Solution:
Public Class SessionAccess Public Shared Property Blah(ByVal session As HttpSessionState) As Integer Get