I am using ASP.NET MVC and Entity Framework. I have an Edit Person web page where person's fields can be edited, then in the post back action, I use the following code.
var person = objectCtx.Persons.Where(s => s.Id == id).FirstOrDefault();
TryUpdateModel(person, form.ToValueProvider());
objectCtx.SaveChanges();
It works great. Howeve...
I use ADO.NET Entity Framework with several data access layer methods that return the same domain entity. Let it be:
class PersonEntity {
public int Id { get; set; }
public string Name { get; set; }
}
and methods return Person entity by different criteria:
PersonEntity GetById(int id) {
return db.Person.FirstOrDefault(x => new ...
I'm looking for an utility class to generate fake entity instances at runtime.
I'm implementing a ASP.NET MVC3 website using EF4 with a code-first approach, so I'd like to run the site before creating any database. The fake instances should contain valid data (hopefully reflecting the various DataAnnotation attributes used in each class ...
Here's the issue:
The database is highly normalized, and one particular query relies on the multiple relationships in the database. The query is designed to join all the tables, construct the entire object, and then return a list of those objects.
In other words this particular query does a lot of work.
Now, the query does only return...
Given this query:
from s in services
select new
{
s.Id,
s.DateTime,
Class = s.Class.Name,
s.Location,
s.Price,
HeadCount = s.Reservations.Sum(r => r.PartySize), // problem here. r.PartySize is int
s.MaxSeats
}
If the service doesn't have any reservations, this exception is thrown:
System.InvalidOperatio...
Is there a way to get the database column DataType length information given a table's EntityType?
Example SQL (SQL Server) that you can run to see precisely what information I am looking for:
select
sys.tables.name as 'Table Name',
sys.columns.name as 'Column Name',
sys.systypes.name as 'DataType',
sys.columns.max_l...
Can someone explain why data binding against a nullable property in an ADO Data Entity Model does not seem to work. I have a decimal field named "Weight" that when it is set to allow nulls in the database, I can not seem to change the value on a windows form. However if I turn off the allow nulls in the database and update the model, t...
Hello,
I am using .NET 4.0 and the entity framework to do some server side validation. I have a simple table called "Contacts" which looks like this:
ID int Dont Allow Nulls
FirstName nvarchar(50) Dont Allow Nulls
SecondName nvarchar(50) Dont Allow Nulls
MobileNumber nvarchar(50) Dont Allow Nulls
HomeNumber nvarchar(50) Allow Nulls
...
Hello,
I have a need to generate SQL queries against a variety of database providers, for database schemas that are not known at compile time. I see that Entity Framework has already done the hard work of providing a SQL dialect called Entity SQL that is translated to native SQL before execution, and I was hoping to take advantage of th...
I have a form that creates a new brand. The user chooses a name, image, and website url for the brand and hits submit. The edit scenario works the same way. The issue I'm having is when creating a new brand, the correct imageId is being posted, and right up to SaveChanges() in my action its correct. When I check the new row in the databa...
Hi everybody, i', starting to work with Entity Framework and i would like to know how to implement a master detail web form that permit the user to insert the details in a datagrid before saving it to the database using entity framework 4.
Thanks in advance.
Jean Carlos
...
Hi, this is the case: ASP.NET MVC C#
Model: I would like to use information defined on three tables, Product - Details - Pictures. I created a ProductRepository and defined a join of the three tables. Finally I select fields from each of these tables.
public IQueryable ProductsList()
{
var db = new Entities();
v...
Hi
Is there a way to make EF model automatically fetch SQL Server extended property into model? I've read about POCO, but I'm a little confused since it states that you should turn automatic code generation off. If you do that, does your model still update automatically when you add new objects? and how should I update my model so it get...
Is it possible to compile queries which will be used with paging and sorting? For example does this make sense:
this.query = CompiledQuery.Compile<...>(
..
from row in dbx.Table select row
)
..
var select = this.query.OrderBy(..).Skip(..).Take(..);
Is this plausible? Or will it recompile every time Order, Skip, Take parameters chang...
I'm trying to implement a transaction with entity framework 4. From what I've read, the code below is correct. The SaveChanges works fine but as soon as I hit the first ExecuteFunction call I get the following exception:
The underlying provider failed on
Open. --->
System.Transactions.TransactionManagerCommunicationException:
...
For a basic ERP (DB with around 150 tables, WinForm app) which would run on a classic LAN network (1 server and up to 25 clients) would you recomend EF4 or DataSet ?
LINQ2SQL is NOT an option !
...
OK, here is the szenario:
I'm coding a .NET 3.5 WPF-Aapplication, using the Microsoft Entity Framework to use a compact database file (.sdf) for storing data. On my first program start a computer-based encryption key is calculated and saved into the registry and my sdf-File should become encrypted with this key (or rather with a somehow...
I have been dealing with this for at least two days now. I don't have a book available to reference, and I cannot for the life of me find an explanation of how this is supposed to work.
What I am trying to do is a simple operation:
Load a create form populated with 3 dropdownlist elements which reference other tables
Fill out the form...
I see there is a similar question asked here but I don't think it was very clear so I'm creating another : http://stackoverflow.com/questions/1239504/entity-framework-inheritance-change-object-type
I have an Entity Student that inherits from an Entity Person.
At some point a Person could become a Student.
Is there any way in Entity Fr...
I'm trying to override the constructor of a partial class in RIA DomainService shared code as follows.
foo.shared.cs:
public partial class Foo
{
private SomeClass _privatevariable;
public Foo(SomeClass variable)
{
this._privatevariable= variable;
}
}
foo is a generated class based on an Entity Framework Model.
When I b...