Tuesday, March 31, 2015

Entity Framework - Error 0019: Each type name in a schema must be unique. Type name was already defined!





I recently used Entity Framework in an Azure WebJob and enjoyed the ease of use so much that I've been slowly converting our web services over to use EF instead of the ADO.NET library we were using before. 

Being that i was about to start writing a "load balancer" of sorts for our Merchant Accounts, i felt this would be the perfect opportunity to make use of EF. 


Once testing the webservices locally proved successful, i published them to my test server. Once i accessed them from there, I kept getting the following error:

The Error 
Schema specified is not valid. Errors: \r\nerror 0194: All artifacts loaded into an ItemCollection must have the same version. Multiple versions were encountered.\r\nRenatus.csdl(708,4) :
error 0019: Each type name in a schema must be unique. Type name `RenatusModel.OrderDetail` was already defined.\r\nRenatus.csdl(725,4) :
error 0019: Each type name in a schema must be unique. Type name `RenatusModel.Order` was already defined.\r\nRenatus.csdl(762,4) :
error 0019: Each type name in a schema must be unique."
Not knowing why i i'd get those errors on the test server, but not locally, i decided to write some Unit Tests to call the Data Layer of my services directly.



[TestMethod]
public void GetMerchant()
{
 PaymentDAO dal = new paymentDAO();
 var merchant = dal.GetCurrentMerhant();
}

public string GetCurrentMerchant()
{
    var merchant = "Merchant1";

    using (Entities context = new Entities())
    {    
        var monthbegin = new DateTime(DateTime.UtcNow.Year,DateTime.UtcNow.Month,1);
        var monthend = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1).AddMonths(1);                    
        var merchants = context.PaymentMerchants.Where(x => x.balance_percentage > 0)
            .Select(x => new
            {
                Merchant = x.db_name,
                Percentage = x.balance_percentage,
                Amount = context.Payments.Where(y => y.IsDeclined == 0 && y.IsCaptured == 1 && y.MerchAcct == x.db_name && y.AddDate > monthbegin && y.AddDate < monthend).Sum(y => y.TotalAmount),
            }).Select(x => new
            {
                Merchant = x.Merchant,
                Percentage = x.Percentage,
                Amount = x.Amount.HasValue ? x.Amount.Value : 20000M
            }).ToList();

        if (merchants.Count() > 0)
        {
            var total = merchants.Sum(y=> y.Amount);
            merchant = merchants.Select(x =>
            new
            {
                Merchant = x.Merchant,
                Percentage = x.Percentage,
                Amount = x.Amount,
                PercentofTotal = total > 0M && x.Percentage > 0 ? ((x.Amount / total) / x.Percentage) * 100M : 0M
            }).MinBy(x=> x.PercentofTotal).Merchant;
        }
    }
    return merchant;
}

As you can see, it's pretty straight forward. Running from my Unit.Tests always returned the name of a Merchant. Running from my WCF Services always returned the above error. The Model above doesn't even reference the tables that the above error was referring to -.-

Upon searching google and finding the many potential solutions for this problem, i was lead to look for a reference to another project with an EF model that had the same name. I did find one, so i removed the reference and removed the .dll and .pdb as suggested, and even tried removing my bin and obj folders entirely to let them get repopulated. This, however, DID NOT fix the problem! 
http://topf5.com/1NEQWbE
http://topf5.com/1MuM4sH

I went back to my Unit Tests to see if the other dll had a similar issue at all, and i found that it was throwing a similar error! UGH! I ran the other test again, just for kicks and giggles and it too was now getting that error where it was previously working! Double UGH! Tested my wcf services locally, in debug mode, and they also had stopped working.

The good news is now i could replicate the error locally, and i could see that although the other model had zero changes made to it since it last worked it was not broken. 

I tried reverting my EF to a previous version wondering if  maybe an update broke the functionality, but that didn't work either.

I made sure all my referenced tables had primary keys on them as suggested by some post online i can no longer find.

I tried deleting my models and recreating them as suggested by another post online.

What FINALLY worked? I recreated one of the models making the EF Model name and the EF Entities name unique to the namespace containing it. 

Amusingly, the old model that wasn't working still didn't work. I checked for old dlls and pdbs that may be referencing the library that was causing conflict but i couldn't find anything, so i just recreated that EF Model using a unique name as well! 

Best Practices for me on this moving forward will be to always make the EF Models uniquely named to the namespace they're in!

Tuesday, March 10, 2015

Whatever you're looking for, you're going to find!


I know that the universe will always support me in whatever energy i'm putting out there! 

Whether i'm consciously creating to see that the plans of my life come to sure and perfect fulfillment, or whether i'm going unconscious leaving the door open for chaos.


So when people say things to me like "I'm not ready" or "I don't know if i have what it takes" there's a moment shortly after where i hear the silence says "And so it is".

They talk to be me about not being sure or clear about a choice they made and if it was the right one. They begin listing off all the reasons why they shouldn't have made that choice instead of trusting in their choice and looking at all the positive things that have come about as a result of that choice. 

If you're looking for a problem, you're going to find it. And any use of tools, talking with friends, or looking for signs in the world around you is all going to have the same result; You are going to find reasons to support your belief there there IS a problem. Until you shift your desired outcome.

If i'm engaging in life, moving forward, something comes up for me, in that very moment i have a choice. 
I can break down or i can break through.

If something happens and i get a thought or feeling that i'm not ready, i can choose to believe it and stop right there, potentially missing out on an opportunity. 

But what is ready?  My ego has long viewed my readiness as making sure that i'm making "the right choice"; That i'm right. 

One of my fears i held onto for most of my life was a fear of being wrong. So if i didn't have enough time to play out all the possibilities in my head, i would just choose out before it began because i couldn't be sure. Then i could be right about not being ready. 

Other times, i would choose in, and then some fear would creep up that i made the wrong decision, and instead of chancing that i might be wrong about continuing with that possibility, i would choose out. As a result things with that possibility wouldn't work out, but then i could be right about my decision to choose out.
100% of the chances i never take, never work out.

As a result of all the missed opportunities i experienced in my desire to be right and my fear of being wrong, i now choose to engage differently. 

When an opportunity arises, i never know how long that window of opportunity will be open. So in that moment i ask myself "Is this an opportunity that i'm willing to miss out on?". If the answer is no, then at that point the question of "am i ready?" or "or do i have what it takes?" doesn't matter, and i don't let ANYTHING get in the way.

I'm ready at the point that i choose to be ready.

I trust that as i play an active role in consciously creating my life that everything around me is going to support me in making my choice turn out for my highest good. And so it is!

Monday, March 9, 2015

If it waddles like a duck, and it quacks like a duck...

...then there might be something for me to take a look at!


Deep in thought, and only aware of the surroundings to the point of being safe in transit, I bring my car to a complete stop and watch as these two ducks, who i assume are taking a stroll on their morning date, waddle across the road in front of me.

The female duck stops in front of my car and looks straight at me as the male duck continues to waddle forward on his stroll. The male duck makes it to the curb while the female duck remains immobile, still staring at me.


Finally the male duck turns around and quickly waddles halfway back to the female duck, quacking all the way. That finally breaks her stare and she quickly waddles to catch up to her partner.


Both are possibilities, and both possibilities have something for me to take a look at! The she duck took a stand, literally, until i was present enough in the moment to get it and connect, and for that i am grateful!


Message received.