.net - List Of Scalar Values From Entity Framework Query?

Dec 22, 2011

I have Customers table in a database. I'd like to create List of CustomerNames using entity framework 4.1. How can I do that in Visual Basic?

Dim customerNames = (From c In _context.Customers
Select New With {c.CustomerName}).ToList()

brings a list of anonymous objects.

View 1 Replies


ADVERTISEMENT

.net - Entity Framework Query With More Than One Join VB?

May 10, 2012

I'm trying to use the Entity Framework to create a complex query and get stuck in the joins. After browsing some of the documentations, I cannot seem to find the correct solution, so maybe someone here can help.

I have a data structure where a family has several family members, each of which can have more than one entry in the income table (on different registration dates) and can have more than one entry in the healthconditions table.

[Code]...

View 1 Replies

Entity Framework Returning Different Data Then DB Query?

Jan 4, 2011

I have a view on some data in my database it returns the data as I would expect, for example

Call Date To From Phone Number
20/1/2010 00:00 23:59 08923233223
20/1/2010 00:00 23:59 08923233245

However when I have added this to my Entity Model and query it I get duplicate(and unexpected) data appearing

Call Date To From Phone Number
20/1/2010 00:00 23:59 08923233223
20/1/2010 00:00 23:59 08923233223

I am simply binding a Entity Data Source to this Entity but I am left scratching my head as to why the data is being returned differently

EDIT: Interestingly this can't be the result of some strange under the hood join as the row counts match as expected. I have also put together a query myself to test with the same odd results.From o In App.Entities.v_PersonalRules Where o.companyid = CompanyID Select o. I am using Visual Studio 2010, .NET 4

EDIT: The front end code is fairly simple

<asp:EntityDataSource ID="EDS_Personal" runat="server" ConnectionString="name=Entities_NEW"
DefaultContainerName="Entities_NEW" EnableDelete="True" EnableInsert="False"
EnableUpdate="True" EntitySetName="v_PersonalRules" EntityTypeFilter="v_PersonalRules" >[code]....

View 2 Replies

.net - Returning A List Using Entity Framework, 'System.Collections.Generic.List Cannot Be Converted To '1-dimensional Array

May 3, 2012

i have issue returning a list in a web method. here is the code

<WebMethod()> _
Public Function getTags(para_parents As String) As List(Of getTypeDetailsByParentName_Result)()
Dim context As New PPEntities

[code]....

the error is

Value of type 'System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)' cannot be converted to '1-dimensional array of System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)'

View 1 Replies

C# - SQL / Entity Framework Error On Date Range Query

Apr 29, 2012

I'm receiving an error when trying to query a range of dates from a MS SQL DB in MVC Entity Framework. Unable to cast the type 'System.Boolean' to type 'System.Data.SqlTypes.SqlBoolean'. LINQ to Entities only supports casting Entity Data Model primitive types. This is our query:

[Code]...

View 1 Replies

Entity Framework Query Returns Same Row Multiple Times

Aug 31, 2011

This is my first time using the Entity Framework and I'm getting some confusing results. I know a particular table contains 3 distinct rows when I run this SQL query:
SELECT * FROM mytable WHERE service_month = 201012

When I run this query against the framework however, I get 3 rows, but they are all copies of the first row (VB syntax).
Dim temp = _context.mytable.Where(Function(x) x.service_month = 201012)
Did I set up something incorrectly? This is how I'd do it with LINQ to SQL.

View 1 Replies

Entity Framework - Query Data In A Navigation Property Table?

Oct 18, 2010

I have a the following setup

m_handsets = From p In RL.App.TComEntities.tblTelephoneNumbers _
Where p.companyId = m_CompanyID _
Select p

m_handsets = DirectCast(m_handsets, ObjectQuery(Of RL.TelephoneNumbers)).Include("tblCalls")

where m_handsets is defined as Private m_handsets As IQueryable(Of RL.tblTelephoneNumbers)

which works as expected however what I want to do know is query the Navigation property (tblCalls) so I can do something like the following From p In m_handsets.tblCalls Where m_handsets.tblCalls.price > 100

I think the complexity comes here because in this instance I could have 5 tblTelephoneNumbers in m_handsets and then x amount of calls for that particular telephone number. I am interested in the tblCalls for each but I would like to filter them all for each tblTelehoneNumber.

Entity Diagram which (hopefully) should illustrate further So I currently know all the handsets that are associated with the company I am interested in. I can also see the calls loaded as a navigation property in debug mode, but I want to say is take this filter (in this example price>100 and apply it to all handsets->calls

View 1 Replies

Asp.net - .NET Entity Framework With WHERE Clause And Boolean Values?

Oct 17, 2011

I'm pretty new to MVC and the Entity Framework, but I'm sure this should be straight forward. I've got a class with a boolean "Active" flag. I then have a function that returns the results by date descending. All I want to do is ensure that only active records are returned. Should be simple, but it fails with the following error:

Error 13 Overload resolution failed because no accessible 'Where' can be called with these arguments: Extension method 'Public Function Where(predicate As System.Func(Of Review, Integer, Boolean)) As System.Collections.Generic.IEnumerable(Of Review)' defined in 'System.Linq.Enumerable': Value of type 'Boolean' cannot be converted to 'System.Func(Of PowellCasting.Models.Review, Integer, Boolean)'.

[Code]...

View 2 Replies

Asp.net - List Of Select Data In Entity Framework (linq)?

May 4, 2012

This is my function:

Public Function GetAllEmployee() As List(Of Employees)
Return DB.Employees.Select(Function(q) New With {q.EmployeeID, q.LastName,q.FirstName}).ToList()
End Function

I'm getting an error:

Value of type System.Collections.Generic.List(Of <anonymous type>) cannot be converted to System.Collections.Generic.List(Of NorthwindModel.Employees).

View 1 Replies

Random Sort List With LINQ And Entity Framework In .net?

Mar 17, 2010

I've seen many examples in LINQ but i'm not able to reproduce the same result in vb.net.

I have following code: Dim context As New MyModel.Entities()

Dim rnd As New System.Random()Dim gardens As List(Of Tuin) = (From t In context.Gardens Where _
t.Approved = True And _
Not t.Famous = True _
Order By rnd.Next() _
Select t).ToList()

[Code]...

View 2 Replies

C# - Are Microsoft Entity Framework And ADO.NET Entity Framework (.edmx) The Same

May 13, 2010

c# - Are Microsoft Entity Framework and ADO.NET Entity Framework (.edmx) the same?

View 7 Replies

.net - Update Non-scalar Entity Properties In EF 4.0?

Apr 27, 2010

At first I was using this as an extension method to update my detached entities...

Public Sub AttachUpdated(ByVal obj As ObjectContext, ByVal objectDetached As EntityObject)
If objectDetached.EntityState = EntityState.Detached Then
Dim original As Object = Nothing

[code]....

Everything has been working great until I had to update non-scalar properties. Correct me if I am wrong but that is because "ApplyCurrentValues" only supports scalars. To get around this I was just saving the FK_ID field instead of the entity object relation. Now I am faced with a many to many relationship so its not that simple. I would like to do something like this...

Dim Resource = RelatedResource.GetByID(item.Value)
Condition.RelatedResources.Add(Resource)

But when I call SaveChanges the added Resources aren't saved. I started to play around with self-tracking entities but it seems they cannot be serialized to ViewState and this is a requirement for me.how to either save my many to many relationships or serialize self-tracking entities?

View 1 Replies

.net - ADO.net Entity Framework - Update Only Certain Properties On A Detached Entity

Jul 22, 2009

I want to update an entity without loading the entity from the database first. I've accomplished this but only by knowing all of the entities properties and then using the "attachto" method. My issues is i don't want my app to need to remember all of the properties. Example:

[Code]....

View 3 Replies

.NET Sample Entity Framework 4.2 Code First Entity Splitting?

Dec 14, 2011

Entity Splitting: one class, two or more tables.Here is how it is done in C#, but I need to get it working in vb.net.One more thing: the class name and table columns do not match, so I have to be able to map that out, too.I have to get this to work this way because the place I'm working at right now is a vb.net only shop and the database schema is fubar, but they have so much (millions) of lines of code done directly against the database in both asp classic, vb.net, AND asp.net webforms that changing the schema right now is not realistically possible.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Post>()
.Map(m =>

[code]....

View 1 Replies

Asp.net - Using ExecuteQuery() With Entity Framework, Entity Class

Jan 16, 2011

I am trying to jump from ASP Classic to asp.net. I have followed tutorials to get Entity Framework and LINQ to connect to my test database, but I am having difficulties figuring out ExecuteQuery(). I believe the problem is that I need an "entity class" for my database, but I can't figure out how to do it. Here is my simple code:

Dim db as New TestModel.TestEntity
Dim results AS IEnumerable(OF ???) = db.ExecuteQuery(Of ???)("Select * from Table1")

From the microsoft example site, they use an entity class called Customers, but I don't understand what that means.

View 1 Replies

Using Statement With A Scalar Query?

May 30, 2012

Can you show a coding example that has the "Using" statement with a scalar query?

View 1 Replies

How To Write A Scalar Query In .NET From A SQL Database

Jul 11, 2011

I am trying to write VB.NET query without writing SQL stored procs. I have already gotten many dataset text queries to work. But I am having trouble with getting this scalar query to work. All I want to do is to get the result of this T-SQL query. How can I code this successfully? select (DateDiff(w, '1/1/' + '2011', getdate())) / 7 AS SELECTED_WEEK (What this code does is it returns the current week of the year). And will this query above return the value as an integer datatype or string?

I tried your answers but it gave me this exception error:

System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is Closed.

View 2 Replies

Return The Count From Scalar Query?

Apr 1, 2009

When I type in cntrows. I get all my table variables except the one I want which is TotalComments. How do I return the Count from my scalar query? I have a Table Adapter named :

[Code]...

View 1 Replies

Entity Framework - C# Or .Net?

Feb 18, 2010

My company is tossing around the idea of using the Entity Framework when it comes out with .NET 4. We are currently a VB.NET shop, but have some interest in switching to C#.Is there any major arguments for or against such a move?Does EF with C# hold any advantages in performance, coding ease, etc over VB.NET?

View 10 Replies

Add A Many-To-Many Relation In Entity Framework?

Apr 17, 2009

I am a newbie. I have been able to Add new entities where there is a One-To-Many Relation. I am having a problem (don't Know how to do it) adding a new Entity when the relation is using Many-To-Many. In my EDM I have:

[Code]....

View 1 Replies

ADO.NET Entity Framework Tools?

Apr 16, 2011

I downloaded the VB 2010 Express software, the total files that we included in the download was 15, but it only loaded up 12 of these files. The following downloads did not get loaded as follows:MS Visual Studio 2010 ADO.NET Entity Framework Tools

MS HelpViewe 1.0 x64

I tried reinstalling the downloads that did not using the VB Express 2010 setup, but they do no appear on the list of downloads, only the SP1 for MS SQL Server 2008 Express Server (x64).Do I require the downloads that did not load.

View 2 Replies

Asp.net Mvc - Entity Framework With Database?

Apr 21, 2012

Here are the entities that i have...

Public Class Account
Public Property AccountId As integer
Public Property AccountDescription As String
Public Property Transactions As List(Of Transaction)
End Class

[Code]...

i would like to make it suc that when i do "db.Account.find(1)" for example it also loads in the list of all transactions which have the coresponding AccountId. I'm not too sure what type of relationship this is?? anyway, right now i can do

Dim acct As Account = db.Account.Find(1) acct.Transactions = from ts in db.transactions select ts where ts.AccountId = acct.accountid but i know this is not the correct way, there must be a way to map this out so that entity can just load everything in one shot right?

View 1 Replies

Entity Data Framework 101

Sep 28, 2011

I am used to using datasets for my projects in terms of data access. I now set myself an easy app to work on in order to learn the entity data framework and how to retrieve & manipulate data.Can anyone guide me through on where to start, what are the advantages of this model, In what scenarios should I choose to use entity framework and what are the things (basis) I should now before starting.My datasets are working fine too. Are there any reasons for me not to stick with that way of accessing data? Or is this something to consider depending on the users of the website (for speed purposes etc.)

View 3 Replies

Entity Framework VB Join

Feb 28, 2012

I'm trying to learn EF in visual basic. I'm struggling with finding any easy to understand simple tutorial of how to do inner joins.

This is the SQL that i'm trying to replicate in EF:

SELECT Quote.LockedDateTime, IncommingQuoteStatus.StatusDesc, Users.FirstName
+ ' ' + Users.LastName AS UserName
FROM Quote

[Code].....

View 1 Replies

WPF With Entity Framework Or Linq?

Feb 8, 2011

I have some basic expirience in Visual Basic and programming Windows Forms programs. I know now that forms programs are no longer updated by Microsoft and that WPF is the way to go. No to mention the slicker interface you can create. I've also noticed that passing SQL strings to a database is no longer the standard either. It's either Entity Framwork or Linq.

So I am going for a fresh approach. I need to develop a program that will access a sql database and be accessed by about 10 concurrent users within the office. What's the best approach in general? Linq or Entity Framework? Also, could you recommend a book or two for someone who is new to WPF and Entity Framework? I do have some programming expirience, just none with WPF or the new ways of ADO.net 4.

View 4 Replies

.net - Entity Framework 4 Save And Cancel?

Nov 3, 2010

I'm currently testing the entity framework 4 for a simple app I wish to build.

how do you save and cancel changes on a record basis? Using the save changes method on the context persists all the changes to the database.

View 3 Replies

.Net Entity Framework - Let Keyword With A Condition

Jul 7, 2011

I need to make a if-else statement in the query meaning I only want to add the OpenAmount to ExpectedAmount if the type = Cash, the problem is that it only gives me the cash row not the other row.

[Code]...

View 1 Replies

Active Record With Entity Framework?

May 14, 2012

I'm working on a project that was built using ADO.NET (raw sql) and Active Record pattern. I am slowly moving it away from ADO.NET to Entity Framework Code First 4.3.Here is an example of the pattern. The interface is a static Load and an instance Save (and Delete -- not shown).

Public Class Part
Public Property Id as Integer
Public Shared Function Load(_id As Integer) As Part

[code].....

View 1 Replies

Asp.net - Accomplish With Entity Framework Without Using Two Contexts?

Apr 6, 2011

I have the following code:

Private Sub btnReserve_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReserve.Click
Using dbContext As pbu_housingEntities = New pbu_housingEntities

[Code].....

executes it always get 0, because the row has not yet been created in the database. I can just move this last bit of code out into its own Context, but is there a better way to do this?

View 2 Replies

Asp.net Mvc - Editable Gridview With Entity Framework

Dec 20, 2011

I am trying to make an MVC index view with bulk editing functionality, but can't seem to get it working. I have replaced the Html.DisplayFor with HTML.editorfor items, and put the whole table in a form which submits back to my index function. I have tried various ideas, but currently my function is

[Code]...

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved