Quantcast
Channel: Entity Framework
Viewing all 10318 articles
Browse latest View live

Edited Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx


Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: Triage notes: this would be indeed a nice addition to SqlFunctions, and I agree with @ErikEJ that there might be other functions that could be added, although it should be ok to add them on demand. My recommendation is to mark this as UpForGrabs. In the meanwhile, it should be possible for application developers to add the function to the SSDL model and invoking it in LINQ, using the steps described here for EDMX: http://blogs.msdn.com/b/alexj/archive/2009/08/07/tip-30-how-to-use-a-custom-store-function.aspx (note that in EF6 we have created a new attribute, DbFunctionAttribte for mapping a method stub for use in LINQ) Or, when using Code First, using similar code to this example: https://github.com/divega/UdfCodeFirstSample

New Post: CF: [Index] data annotation should be a class/table attribute

0
0
For a multi-column index, one has to repeat the index name for each IndexAttribute data annotation over and over again. This requirement is rather error prone (in regard to typos) and it's clumsy.

Moreover, for a multi-column index, the requirement of providing ordinal numbers renders editing an EDM class cumbersome and error prone, too. One always has to make sure the ordinals are continuous and strictly monotonically increasing.

.

Just like the T-SQL syntax suggests, I'd suggest to apply the IndexAttribute on class level.

This way you omit the clumsy name and ordinal requirement. Programmers would just give a comma-separated list of property names by means of an array of lambda expressions - and that's it:
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true)]
public class IndexAttribute : Attribute
{
    public IndexAttribute(Expression<Func<TEntity, Object>>[] properties
                         ,bool[] descending = null)
    {...}
}
Which would result in using something similar to:
[Index(new [] {x => x.Name, x => x.Country}, new [] {false, true})]
public class MyEntity
{
    public int Id;
    public string Name;
    public string Country;
}
.

The original IndexAttribute, which is applied to properties, should be eased to mainly support single column indices by requiring merely the IsUnique constructor parameter:
[AttributeUsageAttribute(AttributeTargets.Property, AllowMultiple = true)]
public class IndexAttribute : Attribute
{
    public IndexAttribute (bool isUnique)
    {...}
}
.

Both new index types should derive an appropriate index name automatically.

Your thoughts?

New Post: Exceptions serialization when running Migrations from VS

0
0
Hi *,

when I run update-database from within VS (2013) and provider throws exception I get following in console.
System.Runtime.Serialization.SerializationException: Type is not resolved for member 'FirebirdSql.Data.FirebirdClient.FbException,FirebirdSql.Data.FirebirdClient, Version=4.5.2.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c'.
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Any idea what could be wrong? I tried stripping down FbException class as much as possible. Now it's just this.
[Serializable]
public class FbException : DbException
{
    public FbException(string message)
        : base(message)
    { }

    public FbException(string message, Exception inner)
        : base(message, inner)
    { }

    public FbException(SerializationInfo info, StreamingContext context)
        : base(info, context)
    { }

    public FbException()
        : base()
    { }
}
Looks like it does not play well with the app domains EF is using. The assemblies are from NuGet (not from GAC).

Any idea what to look for?

JC

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: In the meantime, I asked in the discussions page (https://entityframework.codeplex.com/discussions/572518) why can't the function be added right now, using DbFunctionAttribute, but got no answer...

New Post: Cannot Register a Function

0
0
The reason the function is not recognized by just adding the attribute is that the function is not declared in our provider manifest as a built-in function for SQL Server. The way you can make it to work is by declaring the function in the model (in this case the store model), as I explained in the bug you filed at https://entityframework.codeplex.com/workitem/2586.

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: Note that for Code First the easiest way to declare the function is probably to use this extension: https://codefirstfunctions.codeplex.com/ (@moozzyk updated me with the news that user defined database functions are now supported)

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: @rjperes, I just responded to your discussion thread. In short, the answer is that unlike other built-in functions, our provider manifest does not declare the SQL Format function. Adding the attribute to a method stub is not enough to make EF aware of the function, it just maps the method stub to a function defined in the model or in the provider manifest.

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: @rjperes, @divega - Here is a blog post which explains how to use UDFs with my CodeFirstFunctions convention http://blog.3d-logic.com/2014/08/11/the-beta-version-of-store-functions-for-entityframework-6-1-1-code-first-available/

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: Thanks, but why then a SOUNDEX function, mapped only using DbFunctionAttribute, works? I mean this: [DbFunction("SqlServer", "SOUNDEX")] public static String Soundex(this String value) { throw new Exception(); }

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: @moozyk, thanks, but I also wrote one: http://weblogs.asp.net/ricardoperes/registering-sql-server-built-in-functions-to-entity-framework-code-first

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: I agree with @rjperes. Why does SOUNDEX work fine when set to "SqlServer" but FORMAT does not work with "SqlServer".

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: @rjperes - that's pretty cool!

Created Unassigned: Linq.Any() throw NullReferenceException [2587]

0
0
I couldn't understand what was happening when I use Linq.Any() method to check if EF object contains a specific value, the code throws a NullReferenceException on variable with data prior it's use.

The code below:


public ML.Order FetchOrder(ML.MLDBContext db, long OrderID)
{
if (db == null)
db = new ML.MLDBContext();

//avoided code to fetch the Order details from another system via API

Order apiOrder = api.OrdersGet(OrderID);

//avoided code to test null results

bool isNew = false; //to check if fetched order is new or must be updated on DB

//load from DB
ML.Order dbOrder = db.Orders.Where(o => o.OrderID == apiOrder.id).FirstOrDefault();
if (dbOrder == null)
{
isNew = true;

//avoided code to fill dbOrder with apiOrder data

//Below code check if user bought the same product before

//the error is thrown here but it's not null
string ListingID = apiOrder.order_items.First().item.id;
var previousOrders = db.Orders.Where(order => order.OrderID != apiOrder.id && order.CustomerID == apiOrder.buyer.id && order.SellerID == apiOrder.seller.id).ToList();

foreach (ML.Order prevOrder in previousOrders)
{
if (prevOrder.OrderedItems.Any(i => i.ListingID == ListingID)) //Line who causes the error
{
//code to mask as reordered item
}
}

Some points:

I'm sure "apiOrder.order_items.First().item.id" always have any value.

I'm sure the Order contains the item I'm looking for and the field isn't nullable.

When I comment the line who causes the error, the debug will pass through without errors


To solve this problem, I had to replace **Link.Any()** by **foreach**

foreach (ML.Order prevOrder in previousOrders)
{
foreach (ML.OrderedItem item in prevOrder.OrderedItems)
{
if (item.ListingID == ListingID)
{
//code to mask as reordered item
}
}

}


My doubt is:
Does Linq.Any() or EntityFramework Monitor variables prior to it's declaration and use?

Why the NullreferenceException was trowed on variable prior it usage?

What's the problem using the Linq.Any() method to check the existence of a value inside EF object?

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: @rjperes @goroth beause SOUNDEX *is* declared in the [provider manifest for SQL Server](https://entityframework.codeplex.com/SourceControl/latest#src/EntityFramework.SqlServer/Resources/System/Data/SqlClient/System.Data.Resources.SqlClient.SqlProviderServices.ProviderManifest.xml). By the way, most of the functions declared in the provider manifest are already present in SqlFunctions with the corresponding DbAttribute (unless they are redundant with canonical functions or regular patterns we support in LINQ to Entities).

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: @rjperes @goroth beause SOUNDEX __*is*__ declared in the [provider manifest for SQL Server](https://entityframework.codeplex.com/SourceControl/latest#src/EntityFramework.SqlServer/Resources/System/Data/SqlClient/System.Data.Resources.SqlClient.SqlProviderServices.ProviderManifest.xml). By the way, most of the functions declared in the provider manifest are already present in SqlFunctions with the corresponding DbFunctionAttribute (unless they are redundant with canonical functions or regular patterns we support in LINQ to Entities).

Commented Unassigned: Add the SQL Format function to Entity Framework [2586]

0
0
Add the SQL 2012+ FORMAT function to System.Data.Entity.SqlServer.SqlFunctions
http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Comments: I see... thanks for the info!

New Post: EF7 installing and usage problems

0
0
I am using EF7-beta2-11657 (Visual Studio 2015 Preview).

1) When I try to install EF7, I get the following error:
Unable to resolve dependency 'Ix-Async (>= 1.2.3 beta)'

However, I have found only "1.2.2-withwpa81".


2) I get the following error when trying to get data from SQL Server (I installed EF7 by ignoring dependencies):

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Bonus.exe. Additional information: Could not load file or assembly 'Microsoft.Framework.Logging.Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Commented Issue: UpForGrabs: Perf: TruncateTime Performance Problem [696]

0
0
On SQL Server, called from Entity Framework, the EntityFunctions.TruncateTime function is translated as follows: CAST( convert (datetime2, convert(varchar(255), [Extent1].[DateTimeBucket], 102) , 102) AS datetime2) AS [K5] Converting to a string, then parsing it back to a DateTime is very slow. A far far better version would be: if >= SQL08: CONVERT(DATE, [Extent1].[DateTimeBucket]) else: http://stackoverflow.com/a/353049/122718 (or other techniques) I acknowledge that converting to a varchar works, but it strikes me as a needless performance waste. This change should not require a lot of effort.
Comments: I have submitted a pull request to resolve this issue at https://entityframework.codeplex.com/SourceControl/network/forks/BrandonDahler/EntityFramework/contribution/7750 . Based on my testing, I found that doing CAST(CAST(expression AS DATE) AS DATETIME2) seemed to be the fastest way, but pre-2008 had to use DATEADD(d, DATEDIFF(d, expression, 0), 0) which was still significantly faster. See the pull request for full details (including exact results). Please note that I am not a part of the EF team and therefore cannot provide any insight on if/when my pull request will be accepted/released. Brandon Dahler

Created Unassigned: Make EF load data from database, not cache [2588]

0
0
I have asked this question [here](https://entityframework.codeplex.com/discussions/569592), but got no response.
So, here's the problem. I have lots of tables and lots of columns in them. As I said in that post, when I need fresh data from database, EF takes data not from database, but from local cache. In [similar post](https://entityframework.codeplex.com/discussions/569761) it was insisted to use fresh context every time I need fresh data. So, it means that every time EF will initialize quadrillions of tables and columns? This is not an option, really. Please, add some "LoadDataFromDatabase" method to clear local cache and populate it with fresh data. Thanks.
Viewing all 10318 articles
Browse latest View live




Latest Images