DataSource Controls :: Entity Framework - Send The Values To Be Inserted As Strings To The DAL?

Feb 5, 2010

I've sucefully created a method to insert values through EF, but i've a question (maybe, a newbie question).

Should i send the values to be inserted as strings to the DAL, and then i create the object there or should i create the object in View Layer and then send him to DAL?

Example 1 (DAL):

[Code]....

Example 1 (View Layer, on a click button for example):

[Code]....

Or should i receive the strings in DAL like this: public bool NoticiasInsert(string tituloPT, string tituloEN, string descricaoPT, string descricaoEN)

Then i create the object cdcModel.noticias and set the fields there with the strings values.

What do you advice me to do? I know that both ways works, but i'm trying to develope with better patterns (i don't know if this is the exacly word, sorry my bad english)

cdcModel.noticias campos = new cdcModel.noticias();
campos.tituloPT = "a";
campos.tituloEN = "b";
campos.descricaoPT = "a";
campos.descricaoEN = "a";
if (DAL.NoticiasInsert(campos)

View 1 Replies


Similar Messages:

ADO.NET :: Entity Framework: Getting Key Of Newly Inserted Entity?

Feb 3, 2011

Here's a simple code snippet where I create a new Entity object and call SaveChanges() to create a new record in the mapped database table.

[Code]....

What I'm trying to figure out is whether there is a way to derive this new key for my entity, e, from the ObjectContext, m? The reason for this is that the way my actual code is structured, my entity object is already out of scope at the point where I call the SaveChanges() method.

View 4 Replies

ADO.NET :: Get Last Auto Inserted ID In Identity Column From DB Using Entity Framework?

Mar 25, 2011

I am using below code to get new inserted ID in auto identity column from database.

[code]....

It's working fine when I connect my application with MS Sql, but if I connect with Mysql, it always returns 0 (zero).

Is there any other way to get last inserted ID using Entity Framework?

View 2 Replies

DataSource Controls :: Microsoft Matrix Framework DataGrid - Update Command - Convert Empty Strings To NULL?

Sep 30, 2010

we have a AutoGenerateColumns-enabled WmxDataGrid in which we are able to update table rows in a DataBase connected with a SqlDataSource.

Each time we clear a field an empty string is written to the database where we want to write DBNull values.

At the moment we generate the update string via UPDATE... SET.. and the SQL Server function NULLIF(value, '').

Works proper but when I want to add the values to e.NewValues in BeginUpdate event I'm not able to read the values from the auto generated text boxes. How do I do that? Is there an easier way to automatically convert empty strings to NULL values?

View 2 Replies

Visually Set Controls Datasource From Entity Framework?

Feb 27, 2011

I set up Entity Framework for my Table and Stored Procedure to return data. Created a Domain Class as well.

In Domain Class, I am returning Objects as collection.

On .Aspnet page when I drop a Control(Combo,Dropdown) I can set up the source for the controls visually if the source is table.

However, In domain class I have stored precedure object that return collection of data And I cant not set up visually from Designer, I am only available to write code behind. is it possibble that i can set up from desingner.

View 6 Replies

DataSource Controls :: WEB Services And Entity Framework?

Jan 19, 2010

CAN we use Entity framework in web services.I the following error while the code connects to the database using entity framework

View 3 Replies

DataSource Controls :: Uniqueidentifiers And Entity Framework?

Feb 16, 2010

I have a sql server database that includes the field ArticleID of type uniqueidentifier that is a primary key and is set to be auto-generated by the database when a new article is added.If i generate my entity model and do the following code:

[Code]....

Then a new article is saved to the database but the entity framework must be generating a new blank Guid and saving that to the database rather than allowing it to be auto generated as the articleid that shows up saved is all 0.How can i get the Entity Framework to let the Database generate the ArticleId?

View 3 Replies

DataSource Controls :: How To Use A Stored Procedure In Entity FrameWork

Mar 22, 2010

i joined together more than one entity: Customer, Personel etc. i used inner join structures. if i look adonet entity framework ,5 entities are generated. i need to run this SP in C# side:

[Code]....

LOOK BELOW PİC : you can understand it :

MY C# codes: [Code]....

How can i get all joined data from sql with using randevu.GetRandevular(customerID

View 1 Replies

DataSource Controls :: Entity Framework Deleting Many To Many Relationship?

Jul 9, 2010

I have 3 tables User, role and UserInRole THe entity frame work made entities for User and Role and I have successfully made a join with the user and role entities using user.add(role); but I can't seem to get it to remove the link (I want to retain the user and role just remove their association).

using (ProviderEntities context = new ProviderEntities())
{
User u = context.User
.Where(n => n.ApplicationName == application)
.Where(n => n.Username == username).First();
Roles r = context.Roles
.Where(n => n.ApplicationName == application)
.Where(n => n.RoleName == roleName)
.First();
r.User.Remove(u);
context.SaveChanges();
}

The oposite worked when I did r.User.Add(u); but it wont let me now remove it after it been created. Driving me mad as I can't see where I have gone wrong.

View 1 Replies

DataSource Controls :: Use Database Instead Of MDF File With Entity Framework?

Jan 11, 2010

I transfered my data from MDF files to MS SQL Database, but I can't get it working with entity framework.

My Old connection string is:

metadata=res://*/Models.EntityModel.csdl|res://*/Models.EntityModel.ssdl|res://*/Models.EntityModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|TripsDB.mdf;Integrated Security=True;User
Instance=True;MultipleActiveResultSets=True"

I put all data from TripsDB.mdf to Trips table in local MS SQL 2008 Enterprise database. Also changed connection string to:

Server=WIESIEK;Database=Trips;Trusted_Connection=True;providerName=System.Data.SqlClient;User ID=Jan J. Roman

But my application throws System.ArgumentExceptio with message: The 'server' keyword is not supported.

on line:

private TripsDBEntities2 _entity = new TripsDBEntities2();where TripsDBEntities2 is Entity Framework instance.

View 2 Replies

DataSource Controls :: Stored Procedure In Entity Framework?

Jul 7, 2010

I have a stored procedure that generates a float value. I've added the stored procedure to my edmx file and created a function import, but the function isn't showing up in the object browser or via intellisense.

I'm using Visual Studio 2010 and I've verified that the stored procedure works in SSMS. Here is the current stored proc I'm using:

[Code]....

View 1 Replies

DataSource Controls :: Entity Framework EntityKey (Defaults To 0?)

Feb 6, 2010

CarType
Id - PK
Name
CarDetail
Id - PK
TypeId - FK to CarType

I have this simple example here and I want to insert a new CarDetail into the database but for some reason I cannot get the EntityKey to work in EF4 and Framework4 beta 2.

If i declare the following

car_detail.CarTypeReference.EntityKey = new System.Data.EntityKey("MyDB.CarType", "Id", 1)

Each time i try to call SaveChanges, it throws a INSERT constraint error saying that there is a conflict between CarType and CarDetail with the FK. It just seems like the hard coded 1 for CarType is NOT being passed through but instead the default value of 0. What is going on?

If i call car_detail.TypeId = 1 then it works fine with the INSERT.

Why doesn't the EntityKey method work?

View 1 Replies

DataSource Controls :: Left Join With Entity Framework?

May 17, 2010

how to do this query in EF1:

[Code]....

View 3 Replies

DataSource Controls :: Viewing Fields From Two Tables Using Entity Framework

Mar 17, 2010

I have created a .edmx for the northwind database. When I run the following statement, the correct number of detail records are retrieved and I can access the detail fields, but how do I access the order header record to view OrderDate, ShipAddress, etc...?

[Code]....

View 1 Replies

DataSource Controls :: How To Save Multiple Rows Using ADO.NET Entity Framework

Mar 23, 2010

public void saveOptionalCourses( ArrayList coursesAdded, int studentID)
{
StudentOptionalCoursesXRef XRefObject = new StudentOptionalCoursesXRef();
using (var EntityObject = new SchoolProjectEntities2())
{
foreach ( string list in coursesAdded)
{
XRefObject.StudentDetails = EntityObject.StudentDetails.Where(c => c.StudentID == studentID).First();
XRefObject.OptionalCourses = EntityObject.OptionalCourses.Where(c => c.OptionalCourseName == list).FirstOrDefault();
EntityObject.AddToStudentOptionalCoursesXRef(XRefObject);
}
EntityObject.SaveChanges();
}

with this above method and could save only last row that am returning remaining rows are iterated but are not saving on to database

View 2 Replies

DataSource Controls :: How To Insert A Null Into A Record Entity Framework

Feb 24, 2010

I'm using the linq to entity command to perform a record update. I want to set one of the fields back to NULL but I'm not sure how do it. I have a query such as

Dim record = From r in db.LISTS where r.ID = refID Select r
record.Title = txtTitle.text
if txtDetail.text = "" then
record.Detail =
end if

View 3 Replies

DataSource Controls :: Entity Framework - Parent And Child Relationships?

Feb 4, 2010

I am just getting started with entity framework with asp.net 3.5 using VS 2008

There are two tables, Categories & Subcategories:

Category table: CID, CategoryName Sub Category table: SID, CID, SubCategoryName I would like to get SID, CID, CategoryName, SubCategoryName in the gridview. Just as we write a select statement i.eSelect a.sid, b.cid, b.categoryname, b.subcategoryname from subcategories a inner join categories b on a.cid=b.cid & put the same in a gridview.

I was trying for the whole day & couldnt get atleast one url that would teach how to do it.

View 3 Replies

DataSource Controls :: Entity Framework And Architecture Of Model - Create Application Using EF

Feb 10, 2010

I can't to understand clearly how to create strong and quickly application using EF. For example, I have class ForumPost (table ForumPost) for select one of record I write method like:

public ForumPost ForumPost(int ForumPostID)
{
return
(from i in _dataContext.ForumPostSet
where i.ForumPostID == ForumPostID select i).First();
}

all works. But on page (I use ASP.NET MVC) I should display info from another linked tables, ForumName (each post have ForumID) etc. So, I modify this method to:

public ForumPost ForumPost(int ForumPostID)
{
return
(from i in _dataContext.ForumPostSet
.Include("ChildPosts").Include("ParentPost").Include("Users").Include("Forums").Include("Tags").Include("ForumPostPolls")
where i.ForumPostID == ForumPostID select i).First();
}

ok, all works. Then I want to make some actions in model with ForumPost, i.e.

public void RootPost(int PostID, ref Models.ForumPost Root)
{
ForumPost post = ForumPost(PostID);
if (post.RootPost != null)
{
Root = ForumPost(post.RootPost.ForumPostID);
}
else
Root = post;
}

it works too. But problem is in speed. I not need in RootPost all those includes. So, I should to create one more method like:

private ForumPost ForumPostIncludes1(int ForumPostID)
{
return
(from i in _dataContext.ForumPostSet
.Include("ChildPosts")
where i.ForumPostID == ForumPostID
select i).First();
}

then ForumPostIncludes2, ForumPostIncludes3 etc... second way - redesign RootPost with LINQ expr, not with call another method. But in this way difficulties to change DB. third way? How to do it correctly?

View 1 Replies

DataSource Controls :: Best Way To Handle Inserts For Entities When Using FormViews And Entity Framework 4?

Mar 3, 2010

I am trying to get some guidance with this issue:

I have a Customer object that has two address ID fields (one for HomeAddress and one for WorkAddress)

I am loading the Address Objects by using Include="HomeAddress, WorkAddress" and then binding to the properties using the Navigation Property on the Customer Entity

Can I use just one FormView for doing the Insert/Updates and binding it to an EntityDataSource or would I have to do all the Inserting/Updating manually?

View 1 Replies

DataSource Controls :: Unable To Select And Insert Data In Mapping Table Using Entity Framework

Jan 18, 2010

I have three table like above, table C is mapping table which has foreign key of Table A and B.How can i select and insert data in Table C using Entity Frame Work?

View 2 Replies

DataSource Controls :: Foreign Key Reference Not Updating With ADO.NET Entity Framework Silverlight/Data Service

Apr 8, 2010

I'm trying to insert a new EF object containing a reference to a related table via foreign key, and cannot get the reference stored in the new object. I have two tables in a SQL Server 2008 Database:

Component Templates
PartGroups

with a Foreign Key linking them thus: ComponentTemplates:ID [0..1<->*] PartGroups:ComponentTemplateID

I have imported these tables into a .NET web application project .edmx file (using a new ADO.NET Entity Data Model), and then created a Data Service which I then reference in a Silverlight 3.0 project. The objects are available as expected in the data context called by my Silverlight app and load correctly. Now, when I try to save a reference of ComponentTemplate into a newly created PartGroup, the PartGroup object is created in the database, but the value of ComponentTemplateID in the newly created table record is NULL.

[Code]....

(Note that _ctCtrl.ComponentTemplate is a confirmed non-NULL object reference to the parent object on which PartGroup is a child)

View 2 Replies

ADO.NET :: Default Values In ADO Entity Framework (GetDate())?

Oct 8, 2010

I have a sql server table with a date column that has a default value of GetDate()

this default does not seem to get passed to the EF and so i was wondering what the most elegant way was to code this default value within my asp.net application? I dont want to manually alter the EF Model as i may want to re-import it and dont want to lose these changes.

View 2 Replies

DataSource Controls :: How To Create A Self Association Relation For An Organization Chart Data Tree In Entity Framework

Mar 6, 2010

I,am trying to create a self association relation for an organization chart data tree in Entity Framework,after trying different ways for prevention of exceptions like 3007 and etc. I found that when I put my foreign key in my POCO near Parent and Items navigation properties its work.but I think this is not correct that we have both ParentID scalar property and Parent navigation property. review this and tell me is it correct or not.I'm using VS 2010 RC and ofcource .net framework 4.0 RC

[Code]....

View 2 Replies

C# - NULL Values In Object Properties In Entity Framework?

Feb 12, 2010

Tables: Article, Author, Comment (1 article and 1 author can have * comments)In the database is 1 article, 1 author and 1 comment.

The problem is, that code

myBD my_bd = new myBD();
var articles = by_bd.Article;

works OK, I can see that an Author and an Article has 1 comment. But that code

var comm = (from u in my_bd.Comment
where ......
select u);

returns the comment but it has NULL values in property Article and Author. Why ?

View 2 Replies

ADO.NET :: Entity Framework ContainsAll Matching Multiple Values

Jan 21, 2011

So, have a search form where users can enter one or more keywords, these keywords are then held in a List<string> called keywords. Now using Entity Framework have an Organisation entity with a Name field. What I want to do is select those organisations whose name contains all the keywords. I don't care if they are in the right order or not but it just contain all the keywords. Also organsiations is a big table in the database so I don't want to materialise all the organsiation objects on the server and then loop through them. So what I'm looking for (excuse my LINQ naivety here) is equivalent to the non-existent LINQ statement:

[Code]....

I'm sure this must have already been answered but just can't find it.

View 6 Replies







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