I was able to create an OData (v3) service with WebApiOdata and EntityFramework at server side and Breeze at client side thanks to this document.
Now I'd like to do the same with the version 4 of OData spec. but there is a problem. The EdmBuilder class provided by Breeze depends on the 'Microsoft.Data.Edm' which is related to the version 3.
In the EdmBuilder these 2 lines prevent the project from building:
using Microsoft.Data.Edm.Csdl;
using Microsoft.Data.Edm.Validation;
which is normal, because my project has a reference to 'Microsoft.OData.Edm'(for v4) instead of 'Microsoft.Data.Edm'(for v3).
So I replaced the 2 using statements, by this:
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Validation;
Now the project can build, but at runtime it throws this exception
"Encountered the following errors when parsing the EDMX document:
UnexpectedXmlElement : The element 'Edmx' was unexpected for the root
element. The root element should be Edmx. : (1, 40)"
from the EdmBuilder class at this point:
using (var reader = XmlReader.Create(stream))
{
return EdmxReader.Parse(reader);
}
Is there any way to solve this problem ??? like a new EdmBuilder class that I can download somewhere?
P.S.: I'm using code first migration and this code to configure OData route in the 'WebApiConfig' :
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: "OData",
model: EdmBuilder.GetEdm<MyDbContext>(),
batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
We are currently working on a breeze release that works with OData v 4.0. I will post back here when it is released, which should be in the fairly near future.
Related
I just have tested a great article about WebApi versioning from this website:
https://www.meziantou.net/versioning-an-asp-net-core-api.htm
It works partially: It should generate two Swagger documents, one for each version.
But it actually only generates a document for the given defaultApiVersion. In my example this was set to 2.0. The older WebApi controllers marked with 1.0 do not result into a document. And based on the 2 commands below, I had also expected that the WebApi controllers without any version attribute should be visible in the 2.0 documentation. (Which doesn't happen either).
options.DefaultApiVersion = new ApiVersion(2, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
Can someone give a suggestion about what is happening here?
Kind regards, Mark.
I try to manipulate a CosmosDB (SQL) using entity framework core 3.0 (Microsoft.EntityFrameworkCore.Cosmos 3.0.0).
Everything works fine except when I try to use Contains, StartWith, …
For example:
var query = _context.Challenges.Where(c => c.Name.Contains( "string"));
EF is supposed to translate it to the following SQL (that works perfectly on the CosmosDB – Query Explorer)
SELECT * FROM c WHERE CONTAINS(c.Name, "string")
But I receive the following error message:
The LINQ expression 'Where<Challenge>(\n source: DbSet<Challenge>, \n predicate: (c) => c.Name.Contains(\"string\"))' could not be translated.
Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().
See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Of course, I don’t want to code it like the following, that will execute the entire contains on the client, just to make a simple LIKE…
List<Challenge> entities = _context.Challenges.AsEnumerable().Where(c => c.Name.Contains( "string")).ToList();
Anyone has an idea of to evaluate the "contains" on the server side ?
Note: I try the exact same code using UseSqlServer rather than UseCosmos (and by adding the needed [Key] annotation and creating a SQL server) and it works like a charm.... So it's a definitively a CosmosDB vs EF issue.
By posting the same issue on entity framework core forum (https://github.com/aspnet/EntityFrameworkCore/), the answer was that this feature is not yet implemented:
https://github.com/aspnet/EntityFrameworkCore/issues/18673
https://github.com/aspnet/EntityFrameworkCore/issues/16143
https://github.com/aspnet/EntityFrameworkCore/issues/18451
https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/6333414-implement-like-keyword
For the moment almost all blog posts covering configuration with the new ASP.NET 5 and MVC 6 using json for config is using something like this:
var token = configuration.Get<string>("AppData:CompanyName");
For example this question: How to read AppSettings values from Config.json in ASP.NET Core
But since 6 august this function is removed (if you're using bleeding edge releases) with almost no information on what to use instead.
For me this first occurred when switching to from beta5 to beta6 of Microsoft.Framework.Configuration.Json.
tl;dr;
Do it like this to get it working:
var companyName = Configuration["AppData:CompanyName"];
var branchName = Configuration["AppData:BranchName"];
// etc.
Explanation and source:
This commit removed the Get function:
https://github.com/aspnet/Configuration/commit/ddd7c42ece30f0b7bb57a91ae7a627f2f99b9cf2
Some further comments when digging in the issue can be found here:
https://github.com/aspnet/Configuration/issues/246
Using VS2012, latest SP/update applied.
I have been very frustrated trying to get an ObjectDataSource to work. See http://bit.ly/XTpdvN and http://bit.ly/XTpsHi.
I started a new Web Application project, compiling and running after each step, trying to make the steps as granular as possible.
1) Create new empty web application.
2) Add WebForm1.aspx.
3) Clean, rebuild, run (either View in Browser or in debugger).
4) Add new class to App_Code.
5) Repeat #3.
5) Add existing .mdf to App_Data.
6) Repeat #3.
7) Add Linq-to-Sql class to App_Code (Items.dbml). Leave it empty.
8) Clean, Rebuild, run in Debugger:
Compiler Error Message: CS0234: The type or namespace name 'Linq' does
not exist in the namespace 'System.Data' (are you missing an assembly
reference?)
Source Error:
Line 12: namespace ODS_Restart.App_Code Line 13: { Line 14: using
System.Data.Linq; Line 15: using System.Data.Linq.Mapping; Line 16:
using System.Data;
As far as I can tell, there is nothing in the code in App_Code that needs Linq:
namespace ODS_Restart.App_Code
{
public class BAL
{
public static List<string> GetCountries()
{
return new List<string>() { "USA", "Aus", "NZ"};
}
}
}
As I said, very frustrating. Any insight on how to get past this problem would be greatly apprectiated....
use one wizard for linq to sql program:
step 1. Take new project as windows form application .
step 2. Drag one button and DataGridView from toolbox on it.
step 2. Go to solution explorer. add database(.mdf) file to windows form application project which we've taken.
step 3. Same way by right clicking on windows form application project which we've taken add linq to sql class(.dbml) file.
step 4. Go to Server explorer add table in database taken in step 3. Add data to that table.
step 5. open that .dbml file from solution explorer and drag table created from server explorer on it.
step 6. Open form created in step 2. Double click on that button and add following code:
DataClasses1DataContext obj1 = new DataClasses1DataContext();
List<pp> obj2 = obj.pps.ToList();
dataGridView1.DataSource = obj1;
DataClasses1 is .dbml file added in step 3. pp is table name added in step 4. obj1 and obj2 are objects created. pps represents tablename(pp).
I'm new to ASP.NET and having a problem with a tutorial.
I've created a new MVC4 Project in VS2012 Express for Web.
And I've added a SQL Database with 1 Table "Persons" and filled it with some random testdata:
Id int (primary key, is identity=true)
name varchar(50)
birthdate date
adam 01.01.2001
berta 02.02.2002
As a Model I've used ADO.NET Entity Data Model, named it "PersonsModel.edmx"
and used the Personsdatabase for it.
To see the PersonsModel.Designer.cs file, I activated "Codegeneration Status" to "Standard". Refreshed and clicked on the PersonsModel.Designer.cs file.
But in this file I've errors... So I wanted to use something like this in my controller:
HomeController.cs:
PersonsEntities1 db = new PersonsEntities();
db.person...
but it doesn't work, and I think(?) it's because of the errors in the .Designer.cs file.
PersonsModel.Designer.cs: e.g.:
public PersonsEntities1() : base("name=PersonsEntities1", "PersonsEntities1")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
errors in the base: ... line
and in ContextOptions.
Unfortunately I've no english VS, but it says something like:
The best accordance für the overloaded System.Data.Entity.DbContext(string, System.Data.Entity.Infrastructure.DbCompiledModel)-Method has some invalid arguments
And no definition found for "ContextOptions", there is no method "ContextOptions" which accepts "MvcApplication7.Models.PersonsEntities1" as a first argument.
I'm a bit confused, because I did it like in the tutorial explained.
I think this code is in error:
base("name=PersonsEntities1", "PersonsEntities1")
There is no constructor that takes two strings. Your second argument is supposed to be of type DbCompiledModel. (See here.)
Now, I don't know why your designer would produce code that can't compile, so I'm wondering whether you have the wrong version of Entity Framework installed.
Apparently the problem was VS2012. It all works with VS2010.
I've downloaded the installer again from asp.net/mvc and added Visual Web Developer 2010 Express. After installation of VS2010 and all dependencies I tried the tutorial again and all works fine now. No wrong code in the .Designer.cs file :).
Thanks a lot Ann L. for your support. Your hint (wrong version of Entity Framework installed) prompt me to try another VS version.
In addition I've to say: I also tried VS2012 Ultimate (complete DVD version) but it didn't help.